How to clear badge number while preserving notification center

泄露秘密 提交于 2019-12-01 10:52:40

问题


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


来源:https://stackoverflow.com/questions/16534405/how-to-clear-badge-number-while-preserving-notification-center

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!