How to clear badge number while preserving notification center
Asked Answered
B

3

1

I use [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0] to clear badge number. It works fine but remote notifications are removed at the same time.

There are many other questions to clear notification center but I would NOT like to clear them. I just want to clear number of badge while preserving notifications.

Is there any way to achieve this?

Beaver answered 14/5, 2013 at 3:1 Comment(0)
F
4

One hacky way around this is to set the badge count to a negative value. Negative values aren't shown on the home screen and since they're non-zero, they don't cause the notification center to get cleared.

Try [[UIApplication sharedApplication] setApplicationIconBadgeNumber:-1] and see if it results in the user facing behavior that you want.

Frodeen answered 23/9, 2013 at 14:22 Comment(2)
Strangely this isn't working for me anymore...not sure why, I thought it was working a few weeks ago.Lastex
What's weird in my app is that checking the badge getter shortly after setting to -1 results in 0. Perhaps whatever is altering the value to 0 is triggering the same notification center clear that happens when I set it to 0...Lastex
M
1

As far as I know, it is impossible to set badge value to 0. The application badge value will be shown only when it is more than 0. Otherwise, (in case of 0), it will be just hidden by ios.

Midst answered 14/5, 2013 at 3:58 Comment(1)
Sorry for ambiguity. I would like to clear badge value while preserving notification center.Beaver
S
1
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:-1]

it is not working for me .

but i try this is okay.

UILocalNotification *notification=[[UILocalNotification alloc]init];
notification.applicationIconBadgeNumber=-1;
[[UIApplication sharedApplication] presentLocalNotificationNow:notification];
Sullage answered 20/8, 2016 at 9:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.