问题
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