如何处理不同时间到达的用户数据的多个推送通知? [英] How to handle multiple push notifications with user data arrived at different times?

查看:20
本文介绍了如何处理不同时间到达的用户数据的多个推送通知?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用正在接收从服务器发送到 Apple 后端的 APN.当然,一旦通知到达用户的设备,用户可能无法打开应用程序.与此同时,我的服务器可能会推送更多通知.它们都包含一些在处理通知时很重要的用户数据.那么如何处理呢?iOS 不会捆绑并给我一批,是吗?

My app is receiving APNs sent from server to Apple backend. Naturally a user may not open the app once a notification arrives to user's device. In meantime my server may push more notifications. They all contain some user data that is important when a notification is processed. So how to deal with it? iOS won't bundle and give me a batch, will it?

以下是我将如何解决它的方法,其中没有一个是简单的.

Here are ways how I am going to tackle it, none of which is simple.

  1. 服务器会跟踪未看到的数据,并且在到达新请求时始终发送一批所有新通知,将计数反映为徽章计数.
  2. 通过点击通知弹出窗口打开客户端.在这种情况下,它在 didReceiveRemoteNotification 中有所有需要的数据.
  3. 客户端忽略通知弹出窗口并通过点击应用程序图标打开应用程序(可能稍后).在这种情况下 didReceiveRemoteNotification 不会被调用,因此应用程序必须从服务器获取所有需要的数据.
  4. 服务器从不发送任何用户数据,客户端每次启动时总是检查新内容或在 didReceiveRemoteNotification 中获取数据.
  1. Server keeps track of not seen data and upon arriving a new request always sends a batch of all new notifications, reflecting the count as badge count.
  2. Client is opened by taping on notification popup. In this case it has all needed data in didReceiveRemoteNotification. OR
  3. Client ignores notification popup and opens app (possibly later) by tapping on app icon. In this case didReceiveRemoteNotification is not called and thus app has to fetch all needed data from server. OR
  4. Server never sends any user data and client always checks for new stuff every time it starts or fetches data in didReceiveRemoteNotification.

还有什么吗?我缺少一些更简单的东西?

Anything else? Something simpler I am missing?

推荐答案

数字 4 是正确的方法.无法保证您的任何应用代码在收到 APN 时都会运行,iOS7 除外.因此,当您的应用启动时,它必须向您的服务器检查它应该显示的任何新信息.

Number 4 is the right approach. There is no guarantee that any of your app code will run when an APN is received, except on iOS7. So when your app starts, it has to check with your servers for any new information that it should display.

最简单的编码方式是总是向您的服务器询问要显示的最新信息,而不是依赖 APN 中的信息.仅使用 APN 中的信息来确定要导航到哪些新信息,以便应用显示用户点击的任何内容.

It's simplest to code this to alway ask your servers for the latest information to display, rather than rely on the information in the APN. Use the information in the APN only to determine which new information to navigate to, so that the app displays whatever the user tapped on.

iOS7 改变了这一点,您可以使用 remote-notification 后台模式在推送消息到达时启动.见 https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplicationDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/UIApplicationDelegate/application:didReceiveRemoteNotification:fetchCompletionHandler:

This has changed with iOS7, where you can use the remote-notification background mode to be launched whenever a push message arrives. See https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplicationDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/UIApplicationDelegate/application:didReceiveRemoteNotification:fetchCompletionHandler:

这篇关于如何处理不同时间到达的用户数据的多个推送通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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