清除applicationIconBadgeNumber而不删除通知不起作用 [英] Clear applicationIconBadgeNumber without removing notifications not working
问题描述
我已经阅读了几篇文章(例如这篇 https://forums.developer. apple.com/thread/7598 )设置
I've read in a few posts (like this one https://forums.developer.apple.com/thread/7598) that setting
application.applicationIconBadgeNumber = -1
applicationDidBecomeActive
或applicationWillEnterForeground
上的
允许我清除徽章编号,而无需从通知中心删除通知.当我将application.applicationIconBadgeNumber
设置为负数(如-1)时,它将清除Notification Center
中的所有通知.是否有另一种清除徽章编号而不删除notifications
的方法?
on applicationDidBecomeActive
or applicationWillEnterForeground
would allow me to clear the badge number without removing the notifications from the notification center. When I set application.applicationIconBadgeNumber
to a negative number (like -1) it clears all my notifications from the Notification Center
. Is there another way to clear the badge number without removing the notifications
?
推荐答案
UIApplication.sharedApplication.applicationIconBadgeNumber = -1;
我已经在iOS 12.2中对其进行了测试,并且可以通过远程通知正常运行.
I have tested it in iOS 12.2 and it's working fine for me with remote notification.
通过将接收到的远程通知保存在通知中心中来清除徽章计数.
It is clearing badge count by keeping received remote notification in notification centre.
代码段供参考:
- (void)applicationDidBecomeActive:(UIApplication *)application {
UIApplication.sharedApplication.applicationIconBadgeNumber = -1;
}
这篇关于清除applicationIconBadgeNumber而不删除通知不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!