问题描述
我使用 [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0]
清除徽章编号.它工作正常,但同时删除了远程通知.
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?
推荐答案
解决此问题的一个技巧是将徽章计数设置为负值.负值不会显示在主屏幕上,而且由于它们非零,因此不会导致通知中心被清除.
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.
尝试 [[UIApplication sharedApplication] setApplicationIconBadgeNumber:-1]
并查看它是否会导致您想要的面向用户的行为.
Try [[UIApplication sharedApplication] setApplicationIconBadgeNumber:-1]
and see if it results in the user facing behavior that you want.
这篇关于如何在保留通知中心的同时清除徽章编号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!