ios - 不会为每个推送通知调用 didReceiveRemoteNotification

标签 ios objective-c push-notification apple-push-notifications

似乎如果我同时向同一设备发送多个推送通知,则不会为每个发送的通知调用 didReceiveRemoteNotification。假设我发送了 6 个通知,didReceiveRemoteNotification 平均只被调用 3 次。那就是应用程序当前是否正在运行。但是,如果我在应用程序之外并发送 6 个推送通知,所有推送通知都会发送到通知中心/锁定屏幕。这是预期的行为吗?

最佳答案

这是预期的行为:

Apple Push Notification service includes a default Quality of Service (QoS) component that performs a store-and-forward function.

If APNs attempts to deliver a notification but the device is offline, the notification is stored for a limited period of time, and delivered to the device when it becomes available.

Only one recent notification for a particular application is stored. If multiple notifications are sent while the device is offline, each new notification causes the prior notification to be discarded. This behavior of keeping only the newest notification is referred to as coalescing notifications.

If the device remains offline for a long time, any notifications that were being stored for it are discarded.

虽然您的设备在线,但需要注意的重要一点是,APNs 只会为您的应用程序为每台设备存储一个通知。假设您一次发送 3 个通知。当第二条消息到达时,APN 服务器正在将第一条消息传送到设备。它存储第二条消息。然后第三条消息在第一条消息仍在传递时到达,因此第三条消息会覆盖第二条消息,而第二条消息永远不会传递。

这里是你可能会觉得更有说服力的另一句话:

Some Notifications Received, but Not All

If you are sending multiple notifications to the same device or computer within a short period of time, the push service will send only the last one.

Here's why. The device or computer acknowledges receipt of each notification. Until the push service receives that acknowledgment, it can only assume that the device or computer has gone off-line for some reason and stores the notification in the quality of service (QoS) queue for future redelivery. The round-trip network latency here is of course a major factor.

As described in the Local and Push Notification Programming Guide, the QoS queue holds a single notification per app per device or computer. If the service receives another notification before the one in the queue is sent, the new notification overwrites the previous one.

All of this points out that the intent is that a notification indicates to an app that something of interest has changed on the provider, and the app should check in with the provider to get the details. Notifications should not contain data which isn't also available elsewhere, and they should also not be stateful.

Any push notification that isn't delivered immediately was queued for future redelivery because your device was not connected to the service. "Immediately" of course needs to take latency for your connection into account. Outlying cases would be beyond 60 seconds as APNs will time out at that point.

Source

关于ios - 不会为每个推送通知调用 didReceiveRemoteNotification,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19662881/

相关文章:

ios - 在 Xcode 8 和 Swift 3.0 中删除覆盖后准备 segue 崩溃

ios - 禁用 iPad 上的水平滚动

ios - 如何创建免费的 iOS 开发配置文件

android - 如何向C2DM(安卓推送服务)发送批量请求?

ios - 推送通知未发送至 iPhone 设备

ios - Swift - UITableViewCell 具有自定义类和原型(prototype),在第四个单元格后重复

ios - 主从应用程序背景

在自动布局的情况下,IOS scrollview 不明确的可滚动内容高度

objective-c - 以编程方式添加 UIButton 不会显示

javascript - 如果浏览器关闭/Web 推送,FCM 推送通知会排队