Search code examples
swiftpush-notificationnotificationsremoveall

Notification on icon not going away


I've been playing around with local notification and their alerts. However, now I have it working, one of the previous alerts is still attached to the app icon. It's the normal red circle with a 1 in it. I can't get rid of it. There's no notification in the notification centre (swiping down from home screen). I've tried turning notifications off and on. And even cleaning the project in Xcode. How can I get rid of this?


Solution

  • It's called a badge number.

    You can programmatically adjust it to whatever you want, so to clear it just use:

    [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
    

    In swift its:

    UIApplication.shared.applicationIconBadgeNumber = 0
    

    Note: You might have to set it to 1 and then immediately to 0 in some cases (call the above method twice with different values).