2016-11-23 72 views
0

我可以向AppIcon添加徽章,我無法刪除它。如何刪除Appicon徽章,ios10,swift

我有一個通知輔助類,以刷新徽章號功能,如下圖所示:

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)") 
    } 

當我打印輸出,我看到:

​​

這上設置一個徽章AppIcon。

後來,當我觸發引起badge變量減小的事件我看到:

set app icon badge to: 0 

然而,當我的背景應用程序,並檢查圖標,徽章仍然存在,設置爲1

它好像content.badge根本不起作用。在Apple文檔中,如果徽章號碼爲0,它將刪除徽章,但事實並非如此。正如你所看到的,之後我也嘗試將它設置爲nil

如何從AppIcon中移除徽章?

回答

7

集合徽章號= 0。 像UIApplication.shared.applicationIconBadgeNumber = 0

+0

它的工作原理,謝謝。當它允許我時,我會接受你的答案。似乎有一個10分鐘的門檻。 – toast

+0

您可以將此代碼添加到appdelegate方法中 – Aravi

0

我使用

content.badge = -1 

以除去徽章。