Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
277 views
in Technique[技术] by (71.8m points)

ios - APNS get all push notifications

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...