2

We had implemented following method to receive remote notification and enabled "Background Fetch and Remote Notification under Capabilities of a project". Method is hitting even if app is in foreground or background. But "If app is killed, received notification in background then following method doesn't get called". How to fix this?

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
// Some storage code
}

Advance Thanks for any help !

Sakthimuthiah
  • 2,606
  • 6
  • 26
  • 41
  • How do you kill the app for tests? Docs 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. – psci Oct 08 '15 at 12:21

4 Answers4

4

Killing the app indirectly disables push notifications.

This is because if the user kills the app, the OS will not relaunch it unless the user taps the app icon on the home screen.

This is unfortunate, because most users don't know that killing apps (which is fun!) has these annoying collateral effects.

Rhythmic Fistman
  • 34,352
  • 5
  • 87
  • 159
2

This is from Apple's "App Programming Guide for iOS":

In most cases, the system does not relaunch apps after they are force quit by the user. One exception is location apps, which in iOS 8 and later are relaunched after being force quit by the user. In other cases, though, the user must launch the app explicitly or reboot the device before the app can be launched automatically into the background by the system.

Nikolai Ruhe
  • 81,520
  • 17
  • 180
  • 200
Alex
  • 616
  • 4
  • 11
1

When an app is killed. Push notification will not support. Because your app is no longer running. So, there is no way to receieve you the push notification.

Jamil
  • 2,977
  • 1
  • 13
  • 23
  • Not true. If you enabled the remote notifications background mode, the system launches your app and puts it in the background state when a remote notification arrives. – psci Oct 08 '15 at 12:20
  • Thanks for reply, if background mode launches app automatically and puts in background means then why it is not hitting "didreceiveRemoteNotification" method – Sakthimuthiah Oct 08 '15 at 12:23
  • I'm guessing that you just have wrong test scenario. If you terminate app by slide-up in app manager you won't get `- application:didReceiveRemoteNotification:fetchCompletionHandler:` callback. – psci Oct 08 '15 at 12:34
  • http://stackoverflow.com/questions/19068762/will-ios-launch-my-app-into-the-background-if-it-was-force-quit-by-the-user – Jamil Oct 08 '15 at 12:38
0

If the app is not active, this method won't be called. Instead, if the user launches the app from the notification the app will have a payload in didFinishLaunchingWithOptions, in here you can handle the notification.

If the app isn't opened from the notification, you won't get this.

What exactly are you trying to? You can have the app ask for background time, and execute code as needed.

JDM
  • 883
  • 1
  • 8
  • 20