DonDyck
DonDyck

Reputation: 1471

How to clear push notifications programmatically-iOS

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

Answers (2)

Anit Kumar
Anit Kumar

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

dsgriffin
dsgriffin

Reputation: 68566

You can clear them using setApplicationIconBadgeNumber, e.g.:

[[UIApplication sharedApplication] setApplicationIconBadgeNumber: 0];

Upvotes: 1

Related Questions