Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/104.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何删除Appicon徽标、ios10和swift_Ios_Swift - Fatal编程技术网

如何删除Appicon徽标、ios10和swift

如何删除Appicon徽标、ios10和swift,ios,swift,Ios,Swift,我可以向AppIcon添加徽章,但无法删除它 我有一个通知助手类,具有刷新徽章编号功能,如下所示: import UserNotifications class NotificationHelper { ... //fetch all notifications, and update the tabBarController func refreshTabBarBadge(tabBarController: UITabBarController) { ..

我可以向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
根本不起作用。在苹果的文档中,它说如果徽章编号为0,它将移除徽章,但事实并非如此。如您所见,我还尝试在之后将其设置为
nil

如何从AppIcon中删除徽章?

设置徽章编号=0。 像我用过的UIApplication.shared.applicationBadgeNumber=0

content.badge = -1

移除徽章。

有效,谢谢。当你的回答让我满意时,我会接受的。似乎有一个10分钟的阈值。