How to delete a local notification in iPhone

Viewed 27595

I am making an application that sets a local notification.

Thankfully I was able to set the local notification but I don't know how to delete the notification which is set by my application.

The XCode does provide functionality of delete with removeAllNotifications but you cannot remove specific notifications set by the application.

Thanks a lot.

5 Answers

If you are using User Notifications framework, available since iOS 10.0, given the identifier you provided is foo:

UNUserNotificationCenter.current().removePendingNotificationRequests(withIdentifiers: "foo")
UNUserNotificationCenter.current().removeDeliveredNotifications(withIdentifiers: "foo")

Or in Objective-C :

[[UNUserNotificationCenter currentNotificationCenter] removePendingNotificationRequestsWithIdentifiers:@[@"foo"]];
[[UNUserNotificationCenter currentNotificationCenter] removeDeliveredNotificationsWithIdentifiers:@[@"foo"]];
Related