4

I know this topic has been discussed however i keep seeing conflicting stements and im just getting more and more lost.

I just want to know what happens when my app is in the background and it receives a push notification.

I know that:

While in foreground - application:didReceiveRemoteNotification: is called and there is no alert, badge or sound.

while not launched - alert, badge and/or sound is shown/played and if the user taps the "View/Open" (Action) button of the notification, the app is launched and application:didFinishLaunchingWithOptions: is called and the notification payload is passed, if the user closes the notification and taps the app icon, the same method is called however no information about the notification is passed.

while in background - Here is where im confused. I need to know if being in the background running or suspended makes a difference and in whatever case what method(s) are called and if the alert, badge and/or sound is shown/played.

Thanks.

Richard
  • 41
  • 1
  • 3

1 Answers1

5

You might find this answer to How to respond to push notification view if app is already running in the background useful.

Basically, you can tell whether your app was just brought to the foreground or not in application:didReceiveRemoteNotification: using this bit of code:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
    if ( application.applicationState == UIApplicationStateActive )
        // app was already in the foreground
    else
        // app was just brought from background to foreground
    ...
}
Community
  • 1
  • 1
gerry3
  • 21,420
  • 9
  • 66
  • 74