简体   繁体   English

iOS 设备重启后未发送静默推送通知

[英]iOS Silent Push Notification not delivered after device reboot

While testing the delivery of silent notifications (one which has "content-available": 1 in the payload) to my app I noticed that, after device is rebooted notifications are not delivered.在测试向我的应用程序发送静默通知(在有效负载中具有“内容可用”:1 的通知)时,我注意到,在设备重新启动后不会发送通知。 Sending the same payload works if the app is running in background or foreground but, after device is rebooted, I do not receive the didReceiveRemoteNotification: callback in AppDelegate .如果应用程序在后台或前台运行,则发送相同的有效负载是有效的,但是在设备重新启动后,我没有在AppDelegate中收到didReceiveRemoteNotification:回调。

This happens both on iOS 13 and iOS 12这发生在 iOS 13 和 iOS 12 上

In short:简而言之:

Your notification was probably delayed by the system and will be delivered after some minutes.您的通知可能已被系统延迟,将在几分钟后发送。 You can use the Console.app to filter system logs and try to figure out what's happening under the scenes.您可以使用 Console.app 过滤系统日志并尝试找出幕后发生的事情。

More details:更多细节:

After several attempts I got some insight on the delivery mechanism of the operating system which can help understanding what's happening under the scene.经过几次尝试,我对操作系统的交付机制有了一些了解,这有助于理解场景下发生的事情。

By using the Console.app on macOS, selecting your attached device and filtering logs of a process named " dasd " which contains your bundle identifier (type process:dasd any:YOUR_BUNDLE_ID ) I figured out that the system actually receives the remote silent notification but cancels the attempt to awake my app.通过在 macOS 上使用Console.app ,选择您连接的设备并过滤名为dasd的进程的日志,该进程包含您的包标识符(类型process:dasd any:YOUR_BUNDLE_ID )我发现系统实际上收到了远程静默通知,但是取消唤醒我的应用程序的尝试。

default    15:37:29.955974+0200    dasd    Submitted Activity: com.apple.pushLaunch.YOUR_BUNDLE_ID:7BAB0E at priority 5 <private>
default    15:37:29.958436+0200    dasd    Adding a launch request (<private>) for application <private> by activity <private>
default    15:37:29.958611+0200    dasd    Launch requests for <private>: (null)
default    15:37:29.972714+0200    dasd    com.apple.pushLaunch.YOUR_BUNDLE_ID:7BAB0E:[
    {name: ThunderingHerdPolicy, policyWeight: 1.000, response: {Decision: Must Not Proceed, Score: 0.00, Rationale: [{timeSinceThunderingHerdTriggerEvent < 300}]}}
 ], FinalDecision: Must Not Proceed}
default    15:37:33.505325+0200    dasd    Submitted Activity: com.apple.pushLaunch.YOUR_BUNDLE_ID:B3D6C8 at priority 5 <private>
default    15:37:33.509388+0200    dasd    Adding a launch request (<private>) for application <private> by activity <private>
default    15:37:33.509515+0200    dasd    Launch requests for <private>: <private>
default    15:37:33.509778+0200    dasd    Daemon Canceling Activities: {(
    com.apple.pushLaunch.YOUR_BUNDLE_ID:7BAB0E
)}
default    15:37:33.510334+0200    dasd    CANCELED: com.apple.pushLaunch.YOUR_BUNDLE_ID:7BAB0E at priority 5 <private>!
default    15:37:33.510514+0200    dasd    Removing a launch request for application <private> by activity <private>
default    15:37:33.510693+0200    dasd    Don't have <private> for type 0
default    15:37:33.510865+0200    dasd    Don't have <private> for type 1
error    15:37:33.511162+0200    dasd    Activity <private> not tracked as being started, ignoring it

More precisely I found out that two policies are enforced by the operating system:更准确地说,我发现操作系统执行了两个策略

  • a BootTimePolicy which requires at least 120 seconds to elapse after boot before delivering notifications一个BootTimePolicy ,它在启动后至少需要 120 秒才能传递通知
{name: BootTimePolicy, policyWeight: 0.010, response: {Decision: Must Not Proceed, Score: 0.00, Rationale: [{[Minimum seconds after boot]: Required:120.00, Observed:103.62},]}}
  • a ThunderingHerdPolicy which, in this case, requires at least 300 seconds to elapse after a misterious "ThunderingHerd" event一个ThunderingHerdPolicy ,在这种情况下,在发生神秘的“ThunderingHerd”事件后至少需要 300 秒
    {name: ThunderingHerdPolicy, policyWeight: 1.000, response: {Decision: Must Not Proceed, Score: 0.00, Rationale: [{timeSinceThunderingHerdTriggerEvent < 300}]}}], FinalDecision: Must Not Proceed}

After that, following the logs flow I noticed that the system keeps on evaluating this ThunderingHerdPolicy several times and, after 300 seconds, the silent notification was effectively delivered to my app!之后,按照日志流,我注意到系统会多次评估此ThunderingHerdPolicy300 秒后,静默通知有效地传递到我的应用程序!

So if you are testing the delivery of silent notifications keep in mind that it can be delayed by the system under some circumstances (as Apple says in the docs ).因此,如果您正在测试静默通知的传递,请记住在某些情况下它可能会被系统延迟(正如 Apple 在文档中所说)。 This happens to be true after a device reboot.在设备重新启动后发生这种情况。

Please note that this behaviour is not officially documented and that could change in future releases of iOS.请注意,此行为没有正式记录,并且在 iOS 的未来版本中可能会发生变化。 You should not rely on this but only use it for debugging purposes.您不应依赖它,而仅将其用于调试目的。

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

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