Search code examples
iosswiftxcodeswift3uilocalnotification

How to cancel or delete after seen UILocalNotification in swift3?


I used the following code in my project, but can't delete notification.

UIApplication.shared.cancelAllLocalNotifications()

How to solve this problem? Have anyone this problem? Please help me.


Solution

  • Along with

    UIApplication.shared.cancelAllLocalNotifications()
    

    Try this also

    UIApplication.shared.applicationIconBadgeNumber = 0
    

    I think it will delete all notifications from your notification center panel. Try that out.

    As UIApplication.shared.cancelAllLocalNotifications() only cancels the delivery of all scheduled local notifications and doesn't delete the notification.