如何删除Appicon徽标、ios10和swift
我可以向AppIcon添加徽章,但无法删除它 我有一个通知助手类,具有刷新徽章编号功能,如下所示:如何删除Appicon徽标、ios10和swift,ios,swift,Ios,Swift,我可以向AppIcon添加徽章,但无法删除它 我有一个通知助手类,具有刷新徽章编号功能,如下所示: import UserNotifications class NotificationHelper { ... //fetch all notifications, and update the tabBarController func refreshTabBarBadge(tabBarController: UITabBarController) { ..
import UserNotifications
class NotificationHelper {
...
//fetch all notifications, and update the tabBarController
func refreshTabBarBadge(tabBarController: UITabBarController) {
... some Core Data related stuff to set badge
let content = UNMutableNotificationContent()
if badge > 0 {
content.badge = badge as NSNumber
}
else {
content.badge = 0
content.badge = nil
}
print("set app icon badge to: \(badge)")
}
打印输出时,我看到:
set app icon badge to: 1
这将在AppIcon上设置徽章
然后,当我触发导致badge
变量减少的事件时,我看到:
set app icon badge to: 0
然而,当我将应用程序设置为背景并检查图标时,徽章仍然保留,设置为1
就好像content.badge
根本不起作用。在苹果的文档中,它说如果徽章编号为0,它将移除徽章,但事实并非如此。如您所见,我还尝试在之后将其设置为nil
如何从AppIcon中删除徽章?设置徽章编号=0。
像我用过的UIApplication.shared.applicationBadgeNumber=0
content.badge = -1
移除徽章。有效,谢谢。当你的回答让我满意时,我会接受的。似乎有一个10分钟的阈值。