4

在测试向我的应用程序发送静默通知(在有效负载中有“内容可用”:1)时,我注意到,在设备重新启动后,通知不会被发送。如果应用程序在后台或前台运行,则发送相同的有效负载有效,但是在设备重新启动后,我没有didReceiveRemoteNotification:收到AppDelegate.

这发生在 iOS 13 和 iOS 12 上

4

1 回答 1

7

简而言之:

您的通知可能已被系统延迟,将在几分钟后发送。您可以使用 Console.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

更准确地说,我发现操作系统执行了两个策略:

  • aBootTimePolicy在启动后至少需要 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},]}}
  • aThunderingHerdPolicy在这种情况下,在发生神秘的“ThunderingHerd”事件后至少需要 300 秒
    {name: ThunderingHerdPolicy, policyWeight: 1.000, response: {Decision: Must Not Proceed, Score: 0.00, Rationale: [{timeSinceThunderingHerdTriggerEvent < 300}]}}], FinalDecision: Must Not Proceed}

在那之后,按照日志流,我注意到系统不断评估这ThunderingHerdPolicy几次,300 秒后,静默通知有效地传递到我的应用程序!✌</p>

因此,如果您正在测试静默通知的传递,请记住在某些情况下它可能会被系统延迟(如 Apple 在文档中所说)。在设备重新启动后发生这种情况。

请注意,此行为没有正式记录,并且可能会在未来的 iOS 版本中发生变化。您不应依赖它,而仅将其用于调试目的。

于 2019-10-23T14:42:42.350 回答