Reputation:
Roughly during the third quarter of last year, I was able to use UNNotificationServiceExtension
to not only decrypt incoming push notification contents (a common use case) but also remove previously delivered notifications every time a new one arrived.
I used UNUserNotificationCenter.current().getDeliveredNotifications
to retrieve delivered notifications and then remove those I needed to remove.
However, as the new year rolled up, I suddenly noticed that my app was no longer removing previously delivered notifications from the notification center, despite the code still being present in the service extension and not throwing any errors, and despite the other code in the service extension working just fine.
Upon debugging, I found that UNUserNotificationCenter.current().getDeliveredNotifications
now returns an empty array of notifications even when there are several delivered on the lock screen.
And UNUserNotificationCenter.current().removeAllDeliveredNotifications()
simply does nothing, so even just using that call, without retrieving or filtering delivered notifications, doesn't remove anything.
Does anyone know if there's still a way to accomplish this?
Or could Apple have prohibited this functionality?
Upvotes: 4
Views: 3090
Reputation: 716
It seems apns-collapse-id
APNs request header might be useful here.
It could be used to update former notification content and bring it to the top.
Multiple notifications with the same collapse identifier are displayed to the user as a single notification.
According to the docs, apns-collapse-id
specifies notification identifier
(which normally is random). BE could send a new "delete" notification with the given id in the payload to use it in removeDeliveredNotifications(withIdentifiers:)
function.
Upvotes: 2