我为cloudkit设置了订阅通知.这是我的代码:
nspredicate *predicate = [nspredicate predicateWithFormat:@"TRUEPREDICATE"]; CKSubscription *subscription = [[CKSubscription alloc] initWithrecordtype:recordtype predicate:predicate options:CKSubscriptionoptionsFiresOnRecordCreation]; CKNotificationInfo *notificationInfo = [CKNotificationInfo new]; notificationInfo.alertLocalizationKey =@"New record in cloudKit"; notificationInfo.shouldBadge = YES; notificationInfo.soundName = UIlocalnotificationDefaultSoundName; notificationInfo.shouldSendContentAvailable = YES; subscription.notificationInfo = notificationInfo; CKContainer *container = [CKContainer defaultContainer]; CKDatabase *publicDatabase = [container publiccloudDatabase]; [publicDatabase saveSubscription:subscription completionHandler:^(CKSubscription *subscription,NSError *error) { if (!error) { NSLog(@"no error"); } else { NSLog(@"error%@",error); } }];
工作得很好.问题是徽章,他们看起来像cloudKit没有重置徽章号码,并且即使我将徽章计数设置为零,也会不断增加.
- (void)applicationDidBecomeActive:(UIApplication *)application { application.applicationIconBadgeNumber = 0; }
当应用程序收到新通知时,从0到5(每个新通知增加1,下一次将是6)
你们中的任何人都知道如何从cloudkit中跟踪正确的徽章数量(在Objective-C中)
解决方法
这是
CloudKit won’t reset my badge count to 0的副本
答案是:
处理完通知后,您需要执行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) }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。