0
votes

Looking on web and in many stackoverflow post i have seen that the only way to get remote push notification when the app is in background (and it is launched from icon and not from push message) is to call the server when the app is loaded and get the "last" messages.

I've made this test with instant messaging app (i dont tell the name of the app, but i think you understand):

  • From another device i've sent one message to my device
  • When my device has received the notification i have wait for push notification pop-up to disappear.
  • At this point i have take device offline (no internet connection)
  • I have then open the application and in the list the message was correctly added

So, if i'm in foreground, i can handle the notification on method didReceiveRemoteNotification.

If the app is in background i can handle the nofification in didFinishLaunchingWithOptions (if i launch it with push notification pop-up).

How it's possible to handle the notification when the application is in background and it is launched from icon and not from the push pop-Up?

Thanks

1
If you are using iOS7 or later, you can load data from your server in the background before the user taps the notification (using didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:). Perhaps that's what that unnamed app (let's call it WheresGap) does. - Eran
i have used this method and added [application setMinimumBackgroundFetchInterval:UIApplicationBackgroundFetchIntervalMinimum] and in Capabilities i have enabled Background Modes for "Background Fetch" and "Remote notifications" but when the notification arrive (and the application is in background) the methos is not called. It is called only in Foreground. - Mistre83

1 Answers

1
votes
  • (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {

    UIApplicationState state = [application applicationState];

    if (state == UIApplicationStateActive) { // write code here for handle push notification when app is in foreground } else { // write code here for handle push notification when app is in background } }