iosswiftremote-notifications

How to clear the remote notification in your app?


Is there a way to clear the remote notification from the notification banner when swiping down from the top of the iPhone screen. I tried setting the badge number to zero:

application.applicationIconBadgeNumber = 0 

in delegate didFinishLaunchingWithOptions, and didReceiveRemoteNotification, but it did not clear the notifications. Thanks.


Solution

  • You need to set the IconBadgeNumber to 0 and cancel the current notifications. I never did in swift but I think the code for it would be as bellow:

    application.applicationIconBadgeNumber = 0 
    application.cancelAllLocalNotifications()
    

    Swift 5

    UNUserNotificationCenter.current().removeAllDeliveredNotifications()