CloudKit 不会将我的徽章计数重置为 0 [英] CloudKit won't reset my badge count to 0
问题描述
我尝试了很多方法,但似乎无法从来自 cloudKit 的通知中重置徽章计数.有没有其他人遇到过这个问题.这是我尝试过的:
I've tried a number of things and can't seem to reset the badge count from notifications comings from cloudKit. Has anyone else ran into this problem. Here is what I've tried:
1) 在本地设置徽章计数为 0
1) Set the badge count locally to 0
application.applicationIconBadgeNumber = 0; (temporarily removes the badge count).
运气不好...
2) 调用服务器清除徽章计数
2) Call the server to clear the badge count
CKModifyBadgeOperation *oper = [[CKModifyBadgeOperation alloc] initWithBadgeValue:0];
[oper start];
运气不好...
3) 拉入所有通知更改并将它们标记为已读
3) Pull in all notification changes and mark them all read
NSMutableArray *array = [NSMutableArray array];
CKFetchNotificationChangesOperation *operation = [[CKFetchNotificationChangesOperation alloc] initWithPreviousServerChangeToken:nil];
operation.notificationChangedBlock = ^(CKNotification *notification) {
[array addObject:notification.notificationID];
};
operation.completionBlock = ^{
CKMarkNotificationsReadOperation *op = [[CKMarkNotificationsReadOperation alloc] initWithNotificationIDsToMarkRead:array];
[op start];
};
[operation start];
再次没有运气...
任何建议将不胜感激!谢谢,克里斯
Any suggestions would be greatly appreciated! Thanks, Chris
推荐答案
您需要在处理通知后执行 CKModifyBadgeOperation.
You need to do a CKModifyBadgeOperation after processing your notifications.
这是我在将所有通知标记为已读后调用的 Swift 函数.我将操作添加到 defaultContainer 而不是仅仅启动它 - 我想知道这有什么不同.
Here is my Swift function which I call after marking all the notifications as read. I add the operation to the defaultContainer instead of just starting it - I wonder does that make any difference.
func resetBadgeCounter() {
let badgeResetOperation = CKModifyBadgeOperation(badgeValue: 0)
badgeResetOperation.modifyBadgeCompletionBlock = { (error) -> Void in
if error != nil {
println("Error resetting badge: \(error)")
}
else {
UIApplication.sharedApplication().applicationIconBadgeNumber = 0
}
}
CKContainer.defaultContainer().addOperation(badgeResetOperation)
}
这篇关于CloudKit 不会将我的徽章计数重置为 0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!