[英]How to remove Appicon Badge, ios10, swift
我可以為AppIcon添加徽章,我無法將其刪除。
我有一個通知助手類,帶有刷新徽章編號功能,如下所示:
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
根本不起作用。 在Apple文檔中,它說如果徽章編號為0,它將刪除徽章,但事實並非如此。 如您所見,我也嘗試將其設置nil
。
如何從AppIcon中刪除徽章?
設置徽章編號= 0.像UIApplication.shared.applicationIconBadgeNumber = 0
我用過
content.badge = -1
刪除徽章。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.