push notification handling push notification handling ios ios

push notification handling


The wording here is confusing, especially around the word backgrounding.

When the application is truly not loaded in memory (e,g. when you launch it the splash screen shows up etc), then application:didFinishLaunchingWithOptions is called, and you can get the push notification as follows:

NSDictionary *remoteNotif = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];if(remoteNotif){    //Handle remote notification}

If the app is loaded in memory and is ACTIVE (e.g. the app is currently open on the device) then only application:didReceiveRemoteNotification: is called.

If the app is loaded in memory but is not ACTIVE and NOT BACKGROUNDING (e.g., you launched the app, then pressed the home button, and waited 10 seconds), and then you click the action button on a push notification, only didReceiveRemoteNotification is called.

You can capture this case as follows:

-(void)application:(UIApplication *)app didReceiveRemoteNotification:(NSDictionary *)userInfo{    if([app applicationState] == UIApplicationStateInactive)    {        //If the application state was inactive, this means the user pressed an action button        // from a notification.     //Handle notification    }}


As per iOS 9.1 scenario I have tested push notification in Kill mode where my application is not running in any mode at that time if I tap on push notification than the system will call first,

- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary *)userInfo{//your code execution will here.}

And second method call will be,

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {//Your initial code execution.}

This scenario I have tested in my application.