Notification service extension - hide previous notifications

岁酱吖の 提交于 2019-12-23 22:27:13

问题


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

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

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

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.

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.

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


回答1:


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.



来源:https://stackoverflow.com/questions/59410726/notification-service-extension-hide-previous-notifications

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!