简体   繁体   中英

Is it possible to delete specific push notifications from the Notification Center?

I'd like to be able to delete specific delivered push notifications from the Notification Center.

UNUserNotificationCenter.current().removeAllDeliveredNotifications() obviously can't be used as it will delete everything.

UNUserNotificationCenter.current().removePendingNotificationRequests(withIdentifiers) is ok for a local notification, where you can set the identifier when you create and post the notification. However there appears to be no way of setting the identifier for a push notification, nor if you implement a notification service extension does there appear to be either a way of setting the identifier in there before the push is delivered, nor any way of obtaining whatever internal identifier the OS has assigned.

Is there therefore actually anyway of deleting specific push notifications from the Notification Center?

As per the documentation you can remove a specific notification from the notification center using removeDeliveredNotifications(withIdentifiers:) method.

UNUserNotificationCenter.current().removeDeliveredNotifications(withIdentifiers: [yourNotificationIdentifier])

You can specify an identifier for the remote notification as well, as per the documentation of identifier :

For remote notifications, it is set to the value of the apns-collapse-id key that you specified in the APNs request header when generating the remote notification. If no value is set, the system automatically assigns an identifier.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM