菜鸟教程小白 发表于 2022-12-12 15:52:31

ios - 设备上线后 iOS 推送通知出现异常行为


                                            <p><p>我在 Ionic 应用程序中使用 Parse 推送通知。虽然当设备在线时推送通知在 iOS 和 Android 中都能正常工作,但当设备离线然后在线时,Android 和 iOS 中的行为有很大不同。</p>

<p>在 Android 中,设备离线时发送的所有通知都会被接收。在 iOS 中,会发生以下任一情况:</p>

<ul>
<li>我收到所有推送通知</li>
<li>我没有收到推送通知</li>
<li>我从队列中随机收到一条推送通知</li>
<li>我收到队列中的最后一条通知</li>
</ul>

<p>这种看似随机的行为是在 APNS 中预期的,还是我在 Parse 中遗漏了一些设置?我还读到这种情况不应依赖 APNS。</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p> <a href="https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/APNSOverview.html#//apple_ref/doc/uid/TP40008194-CH8-SW5" rel="noreferrer noopener nofollow">From the official APNS documentation</a> :</p>

<blockquote>
<p>Apple Push Notification service includes a Quality of Service (QoS)
component that performs a store-and-forward function. </p>

<p>If APNs attempts to deliver a notification and the destination device
is offline, APNs stores the notification for a limited period of time
and delivers it when the device becomes available again.</p>

<p><strong>This component stores only the most recent notification per device
and per app. If a device is offline, sending a notification request
targeting that device causes the previous request to be discarded. If
a device remains offline for a long time, all its stored notifications
in APNs are discarded.</strong></p>

<p>Apple Push Notification service includes a Quality of Service (QoS)
component that performs a store-and-forward function. If APNs attempts
to deliver a notification and the destination device is offline, APNs
stores the notification for a limited period of time and delivers it
when the device becomes available again. This component stores only
the most recent notification per device and per app. If a device is
offline, sending a notification request targeting that device causes
the previous request to be discarded. If a device remains offline for
a long time, all its stored notifications in APNs are discarded.</p>
</blockquote>

<p>对于 GCM,您可以使用 <a href="https://developers.google.com/cloud-messaging/server-ref#send-downstream" rel="noreferrer noopener nofollow">collapse keys</a> 实现类似的行为:</p>

<blockquote>
<p>This parameter identifies a group of messages (e.g., with
collapse_key: &#34;Updates Available&#34;) that can be collapsed, <strong>so that only
the last message gets sent when delivery can be resumed.</strong> This is
intended to avoid sending too many of the same messages when the
device comes back online or becomes active (see delay_while_idle).</p>

<p><strong>Note that there is no guarantee of the order in which messages get
sent.</strong></p>
</blockquote>

<p>iOS 上的随机行为看起来很奇怪,但可能只是因为推送通知不是 100% 保证送达,也不是按照它们发送的顺序。</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 设备上线后 iOS 推送通知出现异常行为,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/31545342/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/31545342/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 设备上线后 iOS 推送通知出现异常行为