如何重置徽章应用程序图标编号? [英] How to reset the Badge app icon number?

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

问题描述

我将推送通知集成到 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)

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆