本文介绍了如何重设徽章应用程序图标编号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将推送通知集成到CloudKit,以便iCloud中的每一次更改都将在我的iPhone上弹出一条通知,并且徽章应用程序图标编号将相应地添加一个.但是,当我使用代码时:

I integrated the Push Notification to the CloudKit so that every change in the iCloud will pop up a notification on my iPhone and the badge app icon number will add one correspondingly. However, when I used the code:

application.applicationIconBadgeNumber = 0

要在 applicationDidBecomeActive(_ application:UIApplication)中重设该号码,我注意到徽章应用程序图标的号码确实消失了,但是如果再次收到另一个新通知,该号码将不会从一个开始再次按预期进行,但只需在重置前将其加到原始总数上即可.因此,这个数字越来越大.我想知道如何解决这个问题吗?

to reset that number in the applicationDidBecomeActive(_ application: UIApplication), I noticed that the badge app icon number truly disappeared but if another new notification came again, the number won't start from one again as supposed but just add one to the original total number before the reset. Therefore the number is getting bigger and bigger. I wonder how to solve this problem?

推荐答案

我发现我不仅应该像这样设置应用程序端:

I find that I should not only set the application side like:

UIApplication.sharedApplication().applicationIconBadgeNumber = 0

但是我还应该在CKContainer中设置iCloud端.因此,完整的代码如下:

but I should also set the iCloud side in CKContainer. Therefore, the complete code is like below:

let operation = CKModifyBadgeOperation(badgeValue: 0)
operation.modifyBadgeCompletionBlock = {(error) in
    if let error = error{
        print("\(error)")
        return
    }
    application.applicationIconBadgeNumber = 0
}
CKContainer.default().add(operation)

这篇关于如何重设徽章应用程序图标编号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 00:15