Reputation: 1471
I need to clear push notifications from notification center after the user read them. I know there is cancelAllLocalNotifications method, but how do I clear all remote notifications? As an addition I would like to have the following functionality, if user has 5 messages in notification center, we clear all notifications only after user reads All of them. Any ideas how these can be implemented? Thanks in advance for any help.
Upvotes: 2
Views: 2370
Reputation: 8153
If you want to clear notifications in swift
import UserNotifications
if #available(iOS 10.0, *) {
let center = UNUserNotificationCenter.current()
center.removeAllPendingNotificationRequests() // To remove all pending notifications which are not delivered yet but scheduled.
center.removeAllDeliveredNotifications() // To remove all delivered notifications
}
Upvotes: 5
Reputation: 68566
You can clear them using setApplicationIconBadgeNumber
, e.g.:
[[UIApplication sharedApplication] setApplicationIconBadgeNumber: 0];
Upvotes: 1