APNS get all push notifications

867 views Asked by At

Notifications badge

The server will push a notification when the user start to follow or nego.

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo when the user tap on the notification, this block will be executed, and I will get the notification info.

Currently I'm facing a problem, when there are more than 1 notification being pushed, when the user tap on the first one, then the second one won't be executed. Sometime user don't tap on the notification item in notification centre, but open the app directly, then - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo totally not executed.

Is there any way to get ALL notifications so that I can store the info into NSUserDefaults?

1

There are 1 answers

10
SandeepAggarwal On

Case 1:

When the app is not in memory(neither in background mode nor in foreground mode) the user has two choices

  1. either open the app by clicking on the notification received

  2. or open the app directly by clicking on the app icon

In these cases

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

is called where you can get the notification (if any) using this

NSDictionary* remoteNotification=[launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];

Case 2:

But when the app is either in background or in foreground mode, then

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo

is executed, so there you can fetch your data with respect to the notification received. And if in these modes also user tries to click on the notification then again

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

is called and there you can handle the notification data like in Case 1.

Hope this will help.