APNS 获取所有推送通知 [英] APNS get all push notifications

查看:25
本文介绍了APNS 获取所有推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户开始关注或取消时,服务器会推送通知.

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

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo 当用户点击通知时,将执行此块,我将获得通知信息.

- (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.

目前我面临一个问题,当推送的通知超过 1 个时,当用户点击第一个,然后 第二个 不会'被执行.有时用户不点击通知中心的通知项,而是直接打开应用程序,然后 - (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.

有什么方法可以获取所有通知,以便我可以将信息存储到 NSUserDefaults 中?

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

推荐答案

案例 1:

当应用不在内存中时(既不在后台模式也不在前台模式)用户有两种选择

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

  1. 点击收到的通知打开应用

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

或直接通过点击应用图标打开应用

or open the app directly by clicking on the app icon

在这些情况下

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

在您可以使用此获取通知(如果有)的地方调用

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

NSDictionary* remoteNotification=[launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];

情况 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

被调用,然后您可以像案例 1 一样处理通知数据.

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

希望这会有所帮助.

这篇关于APNS 获取所有推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆