我为 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 中)