gpt4 book ai didi

iphone - Cloudkit:CKNotificationInfo 徽章值永远不会减少

转载 作者:行者123 更新时间:2023-12-03 19:06:34 25 4
gpt4 key购买 nike

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

关于iphone - Cloudkit:CKNotificationInfo 徽章值永远不会减少,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27245146/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com