iOS Push Notification - How to get the notification data when you click on the app icon instead of notification iOS Push Notification - How to get the notification data when you click on the app icon instead of notification xcode xcode

iOS Push Notification - How to get the notification data when you click on the app icon instead of notification


You can't get remote push payload by launching app from homescreen.

If the push data is important for app use, load it from your server after app launched.


@fannheyward answer is absolutely correct. You cannot get payload when application is launched by tapping app icon.

I have an idea, what if you get to know that some notification is pending when app is launched by tapping app icon. With this knowledge your app can fetch payload from your server.

You can set "Badge" in every such notification and on applicationDidBecomeActive you can check [application applicationIconBadgeNumber] > 0 to know that some notification is active. After fetching payload from your server you can set it to 0 like below

[UIApplication sharedApplication] setApplicationIconBadgeNumber:1];[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];

Please note: This means your app will have badge displayed over it when notification is received. I am not sure of the behaviour when badge is disabled by user from settings.


If your application target is over iOS7, you can do only if application is alive in backgroud.

In the capabilities settings at Xcode, you should enable Background Modes>Remote notifications, and write below code.

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler{     // save userInfo in NSUserDefaults    completionHandler( UIBackgroundFetchResultNoData );}

If you want to test it, it will be helpful to use https://github.com/acoomans/SimulatorRemoteNotifications

  • From the server side, make sure to set content-available property with a value of 1

For this to work I also had to check the background fetch box.