Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove “local or remote notifications” from notification center

I need to clear all notifications from my notification centre.I tried to cancellAllLocalNotification and UIApplication.shared.applicationIconBadgeNumber = 0 but its not working.i am using swift 4 and xcode 10.1 and ios 12.Anyone can help me..

like image 416
bablu s nair Avatar asked Oct 18 '25 07:10

bablu s nair


1 Answers

cancellAllLocalNotification is deprecated from iOS 10. from appledoc

Deprecated

Use the UNUserNotificationCenter class to schedule local notifications instead.

Use

UNUserNotificationCenter.current().removeAllDeliveredNotifications() // For removing all delivered notification
UNUserNotificationCenter.current().removeAllPendingNotificationRequests() // For removing all pending notifications which are not delivered yet but scheduled. 

From Delivered Removal appledoc

Use this method to remove all of your app’s delivered notifications from Notification Center. The method executes asynchronously, returning immediately and removing the identifiers on a background thread. This method does not affect any notification requests that are scheduled, but have not yet been delivered.

From Pending Removal appledoc

This method executes asynchronously, removing all pending notification requests on a secondary thread.

like image 80
Ratul Sharker Avatar answered Oct 20 '25 22:10

Ratul Sharker