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?

- 33,269
- 19
- 164
- 293

- 2,923
- 2
- 20
- 35
-
1You might want to check your devices settings for background fetching go to Settings->General->Bacgkround App Refresh and make sure the appropriate settings are activated. – Yogurt Feb 15 '14 at 02:06
-
possible duplicate of [iOS 7 Background Fetch - Will iOS launch my app into the background if it was force-quit by the user?](http://stackoverflow.com/questions/19068762/ios-7-background-fetch-will-ios-launch-my-app-into-the-background-if-it-was-fo) – Andrew Jun 18 '14 at 13:29
8 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?

- 1
- 1

- 6,272
- 4
- 28
- 34
-
4Though it seems confusing that it's said that the method will be called when the application is not running at all, though it won't run if the application has been forcibly closed. Is that another application state? – Yogurt Feb 20 '14 at 01:22
-
6It is not another application state, iOS sees forcibly closing the app as the user not wishing to have ANY process thread run by that app until it is next launched. It is working as Apple intends, though their design reasoning is questionable if not altogether ass backwards and stupid with how people actually use the app switcher – Jeremy Mar 03 '14 at 09:07
-
-
@VanDuTran Good point. I haven't checked. Has anyone checked this on iOS 8? I assume they haven't changed it but I'm not sure – nvrtd frst Apr 10 '15 at 20:19
-
1
-
1`application:didReceiveRemoteNotification:fetchCompletionHandler:` is needed for iOS 9. – Michael Apr 13 '16 at 20:00
- (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;
}

- 4,241
- 10
- 40
- 81

- 309
- 3
- 5
-
2-1, it's not process under force-quit. Code above runs when user launch application by tapping notification button. – dimpiax Mar 23 '15 at 00:20
-
1
-
This really solves the problem! In `application:didReceiveRemoteNotification:` we get that notification "as usual". – Dmitry Isaev Sep 01 '15 at 15:49
The app should be launched even if it is not running. The Apple documentation says:
When this value is present and a push notification arrives on a device, the system sends the notification to your app (launching it if needed) and gives it a few moments to process > the notification before displaying anything to the user. (iOS App Programming Guide)
When a push notification arrives, the system displays the notification to the user and launches the app in the background (if needed) so that it can call this method. (UIApplicationDelegate Protocol Reference)
Unlike the application:didReceiveRemoteNotification: method, which is called only when your app is running, the system calls this method regardless of the state of your app. If your app is suspended or not running, the system wakes up or launches your app and puts it into the background running state before calling the method. (UIApplicationDelegate Protocol Reference)
However when testing with "content-available":1 pushes the app is never launched when it is not running. When the app is suspended it works.
Did you find yourself a solution Wes?
-
@ emiel : I need your help for when my app is terminated / suspended . now i get one notification and send data to server without open app . how it is possible or which method call of UIApplicationDelegate Protocol Reference – Bhadresh Sonani May 13 '17 at 10:59
When your app has been force-quitted that method is not called. Instead, as usual, (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
is called.
If the app was opened by tapping "Open" in a notification-popup, the notification is inside launchOptions
.
Get the push-notification dictionary like this:
NSDictionary * pushNotificationUserInfo = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (pushNotificationUserInfo)
{
// call your handler here
}

- 5,135
- 7
- 42
- 52
As documented by Apple, the new multitasking API (fetch and remote-notification) will work only when the app in the suspended/background/foreground state.
In the background/foreground state, then
application:didReceiveRemoteNotification:fetchCompletionHandler
will get triggered.In the Suspended state, then
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
will get triggered.In the Not Running state (your case),
application:didReceiveRemoteNotification:fetchCompletionHandler
never gets triggered.
Please refer to the Apple documentation for more about app states.
-
6"Unlike the application:didReceiveRemoteNotification: method, which is called only when your app is running, the system calls this method regardless of the state of your app. If your app is suspended or not running, the system wakes up or launches your app and puts it into the background running state before calling the method.". are you sure? – lucaconlaq Sep 28 '13 at 15:40
-
if the app is in "Not Running" state. remote notification never wake up the app. – Nandha Oct 07 '13 at 11:48
-
2I agree with Luka's comment. The answer is not correct. application:didReceiveRemoteNotification:fetchCompletionHandler: gets called even if the app is suspended, not running at all, or backgrounded. Also worth noting that the above method is iOS 7 only. – nvrtd frst Feb 11 '14 at 09:26
-
1@Nandha yes I have. Just to be clear, the method that is being asked about here is `application:didReceiveRemoteNotification:fetchCompletionHandler:` which is different from `application:didReceiveRemoteNotification:` Here is the [apple documentation](https://developer.apple.com/library/ios/documentation/uikit/reference/UIApplicationDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/UIApplicationDelegate/application:didReceiveRemoteNotification:fetchCompletionHandler:) for the first method. – nvrtd frst Feb 14 '14 at 20:10
-
1Also worth noting: when receiving the push, the app is only woken up "if needed" to call the `application:didReceiveRemoteNotification:fetchCompletionHandler:` method. i.e. within the push notification payload, you have to set the "content-available" flag (see [SO answer](http://stackoverflow.com/a/19403462/1374512)). The method will be called _again_ if the user then opens the app by tapping the notification. – nvrtd frst Feb 14 '14 at 20:39
If you force quit an app from the application switcher, it will not be woken in the background (via any means) until after the next time it is next launched. When you force quit an app, you are effectively saying to the OS that you do not want this app to run at all, even if a background event would normally have woken it.
This is worth watching out for during testing, as you may have force quit the app in order to check that it gets launched via the push notification when the app is not running. In fact, your use of force quit will be the reason why it doesn't get launched.

- 1,356
- 1
- 8
- 3
To whom concern in Swift 2.0 I've solved my problem like this is for the background
if let remoteNotification = launchOptions?[UIApplicationLaunchOptionsRemoteNotificationKey] as? NSDictionary {
pushNotificationAction(remoteNotification as [NSObject : AnyObject])
}

- 1,492
- 5
- 25
- 51
I recently met the same problem, and I found Apple updated their documentation and says:
However, the system does not automatically launch your app if the user has force-quit it. In that situation, the user must relaunch your app or restart the device before the system attempts to launch your app automatically again.
application(_:didReceiveRemoteNotification:fetchCompletionHandler:)
So I guess there's no way to do anything when the app is killed by force quit?

- 191
- 1
- 13