更新已传递的通知 ios 10 [英] Updating a delivered notifications ios 10

查看:17
本文介绍了更新已传递的通知 ios 10的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

如果上线通知应该是a is online"如果 b 也在线,则通知消息应更新为a 和 b 在线"如果 c 也在线,则通知消息应更新为a、b 和 c 在线"等等..

我使用了这个问题的答案

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

apns-collapse-id

<块引用>

显示多个具有相同collapse identifier的通知作为单个通知发送给用户.这个键的值不能超过 64 个字节.有关更多信息,请参阅 服务质量,存储转发和合并通知.

来自 Apple 文档:

<块引用>

要允许合并*类似的通知,您可以包含一个通知请求中的折叠标识符.通常,当一个设备在线,您发送到 APNs 的每个通知请求导致向设备发送通知.然而,当apns-collapse-id 键出现在你的 HTTP/2 请求头中,APNs合并该键值相同的请求.例如,两次发送相同标题的新闻服务可以使用相同的两个请求的折叠标识符值.然后 APN 将合并将两个请求合并为一个通知,以交付给设备.有关 apns-collapse-id 键的详细信息.

<小时>

*:聚在一起形成一个整体

I am trying to update an already delivered notification on iOS 10 which is a new feature. I am using an api call to send a push notification through firebase.

If a comes online notification should be "a is online" If b also comes online notification's message should be updated to "a and b are online" If c also comes online notification's message should be updated to "a,b and c are online" and so on..

I have used answer from this question How can I removed previously delivered notifications when a new notification arrives with UNUserNotificationCenterDelegate in iOS 10?. Whenever my backend sends a notification I wrote a logic in willPresentNotification to get the exact message needed and update an existing notification message.

But it only works only when the app is in foreground or background. If app is terminated then there is nothing in the frontend that can get executed to update the notification message. So every time backend sends a notification

I get "a is online", "b is online" and "c is online" all separate notifications.

So, how to get the desired behaviour from backend?? Do I have to save the identifiers of the notifications that I push, in the db and use them to update the message remotely?? Does iOS even allow a backend server to get the notification details from notification centre of a remote device?? If we use the identifier from backend will it update the message accordingly??

Thank you

解决方案

Each time you create an updated notification...just use the same identifier. For more see this moment for the WWDC video.

The above answer is for local notifications but you're looking for remote notifications...

Still see the same moment to get the idea...the only difference is that for local notifications you have identifier...for remote notifications you have apns-collapse-id header:

So just give a value to apns-collapse-id and each time you send a new one it will update the previous one. Obviously if the user is in the app then you're out of luck, because they've already received the notification. This would only work if the user hasn't opened the notification yet (nor is in the app). If they have opened it then a new notification is sent.

apns-collapse-id

Multiple notifications with the same collapse identifier are displayed to the user as a single notification. The value of this key must not exceed 64 bytes. For more information, see Quality of Service, Store-and-Forward, and Coalesced Notifications.

From Apple docs:

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 apns-collapse-id key.


*: come together and form one mass whole

这篇关于更新已传递的通知 ios 10的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆