iOS 11中已弃用CKModifyBadgeOperation.有人知道替代方法吗? [英] CKModifyBadgeOperation is deprecated in iOS 11. Anyone know an alternative approach?
问题描述
我已经搜索过,但找不到示例.我还尝试过修改此代码(建议在其他地方使用( CloudKit不会重置我的徽章数为0 ):
I have searched, and I cannot find an example. I have also tried adapting this code (recommended elsewhere (CloudKit won't reset my badge count to 0):
func resetBadgeCounter() {
let badgeResetOperation = CKModifyBadgeOperation(badgeValue: 0)
badgeResetOperation.modifyBadgeCompletionBlock = { (error) -> Void in
if error != nil {
print("Error resetting badge: \(String(describing: error))")
}
else {
UIApplication.shared.applicationIconBadgeNumber = 0
}
}
CKContainer.default().add(badgeResetOperation)
}
目前可以使用,但不再受支持,并且可能很快就会消失.
This works for now, but is no longer supported, and may go away soon.
我想也许我应该使用CKModfyRecordsOperation或其他一些CKDatabaseOperation,但我什至无法猜测.
I thought perhaps I should use a CKModfyRecordsOperation or some other CKDatabaseOperation, but I can't even guess how.
推荐答案
最好只跟踪您正在计数的项目并自行设置应用程序徽章计数.我引用了其中包含我的商品的本地数据库,然后返回总数并相应地设置了我的应用徽章.
It's probably best to just track the items you are counting and set the app badge count yourself. I reference a local database that has my items in it, and I return the total and set my app badge accordingly.
这篇关于iOS 11中已弃用CKModifyBadgeOperation.有人知道替代方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!