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?

rch850
  • 710
  • 1
  • 5
  • 14

3 Answers3

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.

  • Strangely this isn't working for me anymore...not sure why, I thought it was working a few weeks ago. – TahoeWolverine Feb 25 '16 at 02:54
  • 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... – TahoeWolverine Feb 25 '16 at 04:02
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.

Nick
  • 2,573
  • 19
  • 21
NSUserDefault
  • 1,794
  • 1
  • 17
  • 38
  • Sorry for ambiguity. I would like to clear badge value while preserving notification center. – rch850 May 15 '13 at 00:22
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];
coderyi
  • 11
  • 2