更新已交付的通知iOS 10 [英] Updating a delivered notifications ios 10

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

问题描述

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

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.

如果在线通知应该为在线" 如果b也同时在线,则通知的消息应更新为"a和b在线" 如果c也同时在线,则通知的消息应更新为"a,b和c在线" 等等.

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

我得到"a处于在线状态","b处于在线状态"和"c处于在线状态"所有单独的通知.

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

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

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??

谢谢

推荐答案

每次创建更新通知时...只需使用相同 .有关更多信息,请参见时刻用于WWDC视频.

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...

仍然有相同的想法...唯一的区别是,对于本地通知,您具有identifier ...对于远程通知,您具有apns-collapse-id标头:

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:

因此,只需为apns-collapse-id提供一个值,每次发送一个新值时,它将更新前一个值.显然,如果用户在应用程序中,那么您就不走运,因为他们已经收到了通知.仅当用户尚未打开通知(应用程序中也没有)时,此方法才起作用.如果他们已打开它,则会发送 new 通知.

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

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

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.

摘自Apple文档:

要允许类似通知的合并*,您可以添加一个 通知请求中的折叠标识符.通常,当 设备处于在线状态,您发送给APN的每个通知请求 导致将通知发送到设备.但是,当 您的HTTP/2请求标头APN中存在apns-collapse-id密钥 合并该键的值相同的请求.例如, 两次发送相同标题的新闻服务可以使用相同的标题 两个请求的折叠标识符值.然后,APN会合并 将两个请求合并为一个通知,以传递到 设备.有关apns-collapse-id键的详细信息.

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天全站免登陆