Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clear notifications badge without removing notifications

In my app, I'm receiving push notifications with badge number set to one. When app will start, it should set badges count to 0, so I'm using:

[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];

And it works, but also it removes all notifications from notifications center.
Is there a way to clear badges without removing notifications?

like image 847
zdolniacha Avatar asked May 15 '14 09:05

zdolniacha


People also ask

How do I clear my notification badge?

You can easily clear notification badges on app icons at the same time by dismissing the corresponding notifications. So if you swipe notifications on notification panel, or tap CLEAR.

Is there a way to clear notifications on iPhone?

Handle a notification you receive while using another app: Tap to view it, then swipe up to dismiss it. Clear notifications: Swipe left on a notification or group of notifications, then tap Clear or Clear All.


Video Answer


3 Answers

According to this topic:

How to clear badge number while preserving notification center

setting:

[[UIApplication sharedApplication] setApplicationIconBadgeNumber:-1];

should do the trick.

like image 170
zdolniacha Avatar answered Oct 23 '22 02:10

zdolniacha


With iOS9 directly setting badge to negative still clears notifications. You must fire empty UILocalNotification with negative badgenumber to achieve this.

let ln = UILocalNotification()
ln.applicationIconBadgeNumber = -1
UIApplication.sharedApplication().presentLocalNotificationNow(ln)
like image 7
Juuso Ohra-aho Avatar answered Oct 23 '22 02:10

Juuso Ohra-aho


@feb for ios 9+ you need to set 0 not -1 for that you need to add version condition

    if #available(iOS 9.0, *) {
        UIApplication.shared.applicationIconBadgeNumber = 0
    }else{
        UIApplication.sharedApplication().applicationIconBadgeNumber = -1
    }
like image 2
Kiran Sarvaiya Avatar answered Oct 23 '22 01:10

Kiran Sarvaiya