CloudKit不会重置我的徽章计数为0 [英] CloudKit won't reset my badge count to 0

查看:299
本文介绍了CloudKit不会重置我的徽章计数为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];

和再次没有运气...

And again no luck...

任何建议将是极大的AP preciated!
谢谢,
克里斯

Any suggestions would be greatly appreciated! Thanks, Chris

推荐答案

您需要做CKModifyBadgeOperation 处理您的通知。

You need to do a CKModifyBadgeOperation after processing your notifications.

下面是我的斯威夫特功能,我为已读标记所有通知之后调用。
我的操作添加到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屋!

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