简体   繁体   English

APNS获取所有推送通知

[英]APNS get all push notifications

通知徽章

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. - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo当用户点击通知时,将执行此块,我将获得通知信息。

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. 有时用户不点击通知中心中的通知项,而是直接打开应用程序,然后- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo完全没有执行。

Is there any way to get ALL notifications so that I can store the info into NSUserDefaults ? 有什么方法可以获取所有通知,以便将信息存储到NSUserDefaults

Case 1: 情况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: 情况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. 被调用,您就可以像案例1一样处理通知数据。

Hope this will help. 希望这会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM