iphone – Cloudkit:CKNotificationInfo徽章值永不减少

iphone – Cloudkit:CKNotificationInfo徽章值永不减少,第1张

概述我为cloudkit设置了订阅通知.这是我的代码: NSPredicate *predicate = [NSPredicate predicateWithFormat:@"TRUEPREDICATE"]; CKSubscription *subscription = [[CKSubscription alloc] in 我为cloudkit设置了订阅通知.这是我的代码: @H_502_7@

@H_502_7@

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);                       }                       }];
@H_502_7@工作得很好.问题是徽章,他们看起来像cloudKit没有重置徽章号码,并且即使我将徽章计数设置为零,也会不断增加.

@H_502_7@

- (voID)applicationDIDBecomeActive:(UIApplication *)application{    application.applicationIconBadgeNumber = 0;}
@H_502_7@当应用程序收到新通知时,从0到5(每个新通知增加1,下一次将是6)

@H_502_7@你们中的任何人都知道如何从cloudkit中跟踪正确的徽章数量(在Objective-C中)

解决方法 这是 CloudKit won’t reset my badge count to 0的副本 @H_502_7@

@H_502_7@答案是:
处理完通知后,您需要执行CKModifyBadgeOperation.

@H_502_7@这是我的Swift函数,我将所有通知标记为已读时调用.我将 *** 作添加到defaultContainer而不是仅仅启动它 – 我想知道这有什么不同.

@H_502_7@

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徽章值永不减少全部内容,希望文章能够帮你解决iphone – Cloudkit:CKNotificationInfo徽章值永不减少所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1081081.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存