我该如何处理未读的iOS推送通知? [英] How can I handle unread push notifications in iOS?

查看:149
本文介绍了我该如何处理未读的iOS推送通知?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个5.1的iOS应用程序,注册到APNS服务接收通知。寄存器是成功的,我正确地接收通知。问题是当我尝试处理通知。

I have a iOS 5.1 application that registers to the APNS service to receive notifications. The register is successful and I receive the notifications correctly. The problem comes when I try to handle the notifications.

一旦应用程序正在运行,该方法 didReceiveRemoteNotification 在AppDelegate中被正确调用,从而预期的通知处理。然而,只有当应用程序在前台运行的情况。

Once the application is running, the method didReceiveRemoteNotification in the AppDelegate is called correctly and so the notification is handled as intended. This, however, only happens when the application is running on the foreground.

然而,当应用程序在后台运行,或者干脆停止,该方法不叫。我读过,你应该有些行添加到方法 didFinishLaunchingWithOptions 方法来获得从 USERINFO 词典的通知,和处理。这只是正常,但只有当应用程序通过点击在通知中心通知开幕。这意味着,如果你通过点击它的徽章打开应用程序,或仅仅是不断变化的环境,如果你是在后台运行它,应用程序从未意识到的通知走了进来。此外,如果收到多个通知,我们可以只有通过点击通知中心,这是一种痛苦办理其中一人一次: - )

However, when the application is running on the background or is simply stopped, that method is not called. I've read that you should add some lines to the method didFinishLaunchingWithOptions method to obtain the notification from the userInfo dictionary, and handle it. This works just fine, but ONLY when the application is opened by clicking on the notification at the Notification Center. This means that if you open the application by clicking on its badge, or simply by changing context if you were running it on the background, the app never realises that a notification came in. Additionally, if more than one notification was received, we can only handle one of them at once by clicking on the Notification Center, which is a pain :-)

有什么办法来读取通知中心挂起的通知?我知道有一种方法使用方法 cancelAllLocalNotifications 刷新他们,但我还没有找到一种方法,只是阅读。我真的需要处理他们。我想实现与第三方通知服务器的通信协议,当应用程序来到前台再次检索的信息,但由于信息已经在操作系统中我会觉得奇怪,如果它是不可能以某种方式访问​​它。

Is there any way to read the pending notifications in the Notification Center? I know there is a way to flush them using the method cancelAllLocalNotifications but I haven't found a way to just read them. And I really need to handle all of them. I thought of implementing a communication protocol with the third-party notification server to retrieve the information again when the application comes to the foreground, but since the information is already in the operating system I would find it strange if it's impossible to access it somehow.

所以,没有任何人知道的方式做到这一点?先谢谢了。

So, does anybody know a way to do it? Thanks in advance.

推荐答案

在一个推送通知到达,用户点击取消,您的应用程序已经没有办法再读取推送通知。你必须实现一个独立的功能(最有可能在服务器端)来获取发送到该设备的通知的清单。

When a push notification arrives and the user clicks 'cancel', your app has no way to read that push notification again. You have to implement a separate functionality (most probably on server-side) to fetch a list of notifications sent to this device.

例如,如果聊天功能在您的应用程序提供,您可以通过推送通知发送聊天消息,那么你也应该在服务器上保留聊天消息。在任何推送通知则该聊天消息不会在iOS设备上显示如果用户点击取消。在当一个应用程序来在前台后面这种情况下,您拨打电话到服务器并获取所有过去的聊天消息(通过推送通知发送)。

For example, if a chat functionality is provided in your app and you send chat messages via push notifications then you should also keep chat messages on the server. If a user clicks 'Cancel' on any push notification then that chat message will not be displayed on the iOS device. In that case when a app comes in foreground later, you make a call to the server and fetch all the past chat messages (sent via push notification).

这篇关于我该如何处理未读的iOS推送通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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