How to clear badge number while preserving notific

2019-02-20 02:30发布

问题:

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?

回答1:

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.



回答2:

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.



回答3:

[[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];