通知服务扩展-隐藏以前的通知 [英] Notification service extension - hide previous notifications

查看:157
本文介绍了通知服务扩展-隐藏以前的通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,以仅以以下格式显示通知的消息传递应用程序为例:You have X new messages

Take, for instance, a messaging app that only presents notifications with in this format: You have X new messages

当用户收到消息时,应用程序将显示一条通知:You have 1 new message

When the user receives a message, the app will present a notification: You have 1 new message

当它收到第二条消息时,将显示一个新的通知:You have 2 new messages

When it receives a second message, a new notification will be shown:You have 2 new messages

理想情况下,在收到第二条通知后,应该取消/隐藏第一条通知,因为用户只有2条新消息,而不是1 + 2.

Ideally, after receiving the second notification, the first one should be cancelled/hidden, as the user has only 2 new messages, instead of 1 + 2.

如果使用 UserNotifications 在本地显示通知,则只需使用为两个通知创建UNNotificationRequest时,标识符相同.

If notifications are locally presented using UserNotifications, to fix that you simply have to use the same identifier when creating the UNNotificationRequest for both notifications.

使用Notification Service App Extension时是否可以实现相同的目的?

Is there a way to achieve the same when using a Notification Service App Extension?

推荐答案

这可以通过在服务器端修改通知来完成.您可以设置一个名为apns-collapse-id的标题.有关此操作的更多信息,请参阅Apple的文章.

This can be done by modifying the notification in the server side. There's a header named apns-collapse-id that you can set. More info on how to do so is available in this article by Apple.

具有相同标题的所有通知将合并在一起-也就是说,仅显示最新的通知,而前一条将消失.

All notifications with the same header will be coalesced - that is, only the newest one will be shown, the previous will disappear.

这篇关于通知服务扩展-隐藏以前的通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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