i'm working on big app huge chunk of legacy code. - there's implementation for:
- (void) application:(uiapplication *)application didreceiveremotenotification:(nsdictionary *)userinfo the problem is called when app in foreground or when user taps the notification while app in background. tried implement:
- (void) application:(uiapplication *)application didreceiveremotenotification:(nsdictionary *)userinfo fetchcompletionhandler:(void (^)(uibackgroundfetchresult))completionhandler but app behaves same. in case - method not called when app in background. problem?
implementing didreceiveremotenotification , didreceiveremotenotification:fetchcompletionhandler correct way, need following:
make sure register remote notifications, see documentation here:
- (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions { [[uiapplication sharedapplication] registerforremotenotificationtypes:(uiremotenotificationtypealert | uiremotenotificationtypebadge | uiremotenotificationtypesound)]; return yes; } also make sure edit info.plist , check "enable background modes" , "remote notifications" check boxes:

additionally, need add "content-available":1 push notification payload, otherwise app won't woken if it's in background (see documentation here):
for push notification trigger download operation, notification’s payload must include content-available key value set 1. when key present, system wakes app in background (or launches background) , calls app delegate’s application:didreceiveremotenotification:fetchcompletionhandler: method. implementation of method should download relevant content , integrate app
so payload should @ least this:
{ aps = { "content-available" : 1, sound : "" }; }
Comments
Post a Comment