Chr*_*key 7 push-notification apple-push-notifications ios8 cloudkit cksubscription
我已经尝试了很多东西,似乎无法重置来自cloudKit的通知的徽章数量.有没有其他人遇到过这个问题.这是我尝试过的:
1)将徽章计数本地设置为0
application.applicationIconBadgeNumber = 0; (temporarily removes the badge count).
Run Code Online (Sandbox Code Playgroud)
没运气...
2)调用服务器以清除徽章计数
CKModifyBadgeOperation *oper = [[CKModifyBadgeOperation alloc] initWithBadgeValue:0];
[oper start];
Run Code Online (Sandbox Code Playgroud)
没运气...
3)拉入所有通知更改并将其全部标记为已读
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];
Run Code Online (Sandbox Code Playgroud)
再一次没有运气......
任何建议将不胜感激!谢谢,克里斯
Sar*_*ahR 13
处理完通知后,您需要执行CKModifyBadgeOperation .
这是我的Swift函数,我将所有通知标记为已读时调用.我将操作添加到defaultContainer而不是仅仅启动它 - 我想知道这有什么不同.
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)
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1418 次 |
| 最近记录: |