Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

application:didReceiveRemoteNotification:fetchCompletionHandler Not Called

Tags:

It appears the function application:didReceiveRemoteNotification:fetchCompletionHandler is not called when the app has been forcefully quit. It was my impression that the function would be invoked no matter what state the app was in, but it appears that it is only called if the app is already running in the background. Is there a way to wake up an app in the background if it is not already running using the new iOS 7 remote notification background mode?

like image 505
Wes Cossick Avatar asked Sep 17 '13 17:09

Wes Cossick


2 Answers

application:didReceiveRemoteNotification:fetchCompletionHandler: gets called even if the app is suspended, not running at all, backgrounded, or active. Also worth noting that the method is iOS 7 only. Here is the apple documentation.

HOWEVER if the app was forcibly closed (i.e. by killing with the app switcher), the app will not be launched. (see SO answer) EDIT: I checked this again on iOS 7.1 to see if they fixed this, but it still remains the case that if the app is killed manually, app will NOT be woken up and application:didReceiveRemoteNotification:fetchCompletionHandler: will not be called

When receiving the push, the app is only woken up only "if needed" to call the application:didReceiveRemoteNotification:fetchCompletionHandler: method (i.e. you have to set the "content-available" flag within the push notification payload. See SO answer). The method will be called again if the user then opens the app by tapping the notification.

EDIT: haven't checked this on iOS 8. Has anyone else?

like image 100
nvrtd frst Avatar answered Oct 05 '22 07:10

nvrtd frst


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {      //Remote Notification Info     NSDictionary * remoteNotifiInfo = [launchOptions objectForKey: UIApplicationLaunchOptionsRemoteNotificationKey];      //Accept push notification when app is not open     if (remoteNotifiInfo) {        [self application:application didReceiveRemoteNotification: remoteNotifiInfo];     }      return YES; } 
like image 23
kid Avatar answered Oct 05 '22 09:10

kid