菜鸟教程小白 发表于 2022-12-13 01:07:54

ios - 更新已传递的通知 ios 10


                                            <p><p>我正在尝试更新 iOS 10 上已发送的通知,这是一项新功能。我正在使用 api 调用通过 firebase 发送推送通知。 </p>

<p>如果上线通知应该是“a is online”
如果 b 也上线通知的消息应更新为“a 和 b 在线”
如果 c 也上线通知的消息应更新为“a,b 和 c 在线”
等等..</p>

<p>我已使用此问题的答案 <a href="https://stackoverflow.com/questions/38922892/how-can-i-removed-previously-delivered-notifications-when-a-new-notification-arr" rel="noreferrer noopener nofollow">How can I removed previously delivered notifications when a new notification arrives with UNUserNotificationCenterDelegate in iOS 10?</a> .
每当我的后端发送通知时,我都会在 willPresentNotification 中编写一个逻辑来获取所需的确切消息并更新现有的通知消息。</p>

<p>但它仅在应用程序处于前台或后台时才有效。如果应用程序被终止,那么前端就没有任何东西可以执行来更新通知消息。所以每次后端发送一个通知</p>

<p>我收到“a 在线”、“b 在线”和“c 在线”所有单独的通知。</p>

<p>那么,如何从后端获得所需的行为?我是否必须将我推送的通知的标识符保存在数据库中并使用它们远程更新消息? iOS是否甚至允许后端服务器从远程设备的通知中心获取通知详细信息?如果我们使用来自后端的标识符,它会相应地更新消息吗??</p>

<p>谢谢</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p><s>每次您创建<em>更新</em>通知...只需使用<strong>相同</strong> <code>identifier</code>。有关更多信息,请参阅 <a href="https://developer.apple.com/videos/play/wwdc2016/707/?time=1120" rel="noreferrer noopener nofollow">moment</a>用于 WWDC 视频。</s></p>

<p>以上答案适用于<em>本地通知</em>,但您正在寻找远程通知...</p>

<p>仍然看到同一时刻得到这个想法...唯一的区别是对于本地通知,您有 <code>identifier</code>...对于远程通知,您有 <code>apns-collapse-id</code> 标题:</p>

<p> <a href="/image/8O3YX.png" rel="noreferrer noopener nofollow"><img src="/image/8O3YX.png" alt="enter image description here"/></a> </p>

<p>所以只要给 <code>apns-collapse-id</code> 一个值,每次你发送一个新的,它都会更新前一个。显然,如果用户在应用程序中,那么您就不走运了,因为他们已经收到了通知。这仅在用户尚未打开通知(也不在应用程序中)时才有效。如果他们已打开它,则会发送 <em>new</em> 通知。</p>

<p> <a href="https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingwithAPNs.html#//apple_ref/doc/uid/TP40008194-CH11-SW13" rel="noreferrer noopener nofollow"><code>apns-collapse-id</code></a> </p>

<blockquote>
<p>Multiple notifications with the same <code>collapse identifier</code> are displayed
to the user as a single notification. The value of this key must not
exceed 64 bytes. For more information, see <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">Quality of Service,
Store-and-Forward, and Coalesced Notifications</a>.</p>
</blockquote>

<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 Apple docs:</a> </p>

<blockquote>
<p>To allow the coalescing* of similar notifications, you can include a
collapse identifier within a notification request. Normally, when a
device is online, each notification request that you send to APNs
results in a notification delivered to the device. However, when the
apns-collapse-id key is present in your HTTP/2 request header, APNs
coalesces requests whose value for that key is the same. For example,
a news service that sends the same headline twice could use the same
collapse identifier value for both requests. APNs would then coalesce
the two requests into a single notification for delivery to the
device. For details on the <code>apns-collapse-id</code> key.</p>
</blockquote>

<hr/>

<p>*:聚在一起形成一个整体</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 更新已传递的通知 ios 10,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/43463175/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/43463175/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 更新已传递的通知 ios 10