我这样设置我的订阅:
-(voID)addSubscriptions{ nspredicate *predicate = [nspredicate predicateWithFormat:@"TRUEPREDICATE"]; CKSubscription *newRecordSub = [[CKSubscription alloc] initWithrecordtype:_recordtypename predicate:predicate options:CKSubscriptionoptionsFiresOnRecordCreation | CKSubscriptionoptionsFiresOnRecordUpdate | CKSubscriptionoptionsFiresOnRecordDeletion]; CKNotificationInfo *noteInfo = [CKNotificationInfo new]; noteInfo.alertbody = @"Update!"; noteInfo.shouldBadge = YES; noteInfo.soundname = UIlocalnotificationDefaultSoundname; newRecordSub.notificationInfo = noteInfo; CKContainer *container = [CKContainer defaultContainer]; CKDatabase *privateDatabase = [container privateCloudDatabase]; [privateDatabase saveSubscription:newRecordSub completionHandler:^(CKSubscription *subscription,NSError *error) { }];}
问题1:
在创建我的订阅时,我当然只需要将其保存到我的容器一次吗?由于这称为加班,应用程序运行,我得到一个错误只是说,重复订阅,所以应用程序按预期工作,但我应该以不同的方式接近它而不是每次都运行?
接下来我设置接收我的AppID通知并在我的AppDelegate中注册.
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categorIEs:nil]; [application registerUserNotificationSettings:settings]; [application registerForRemoteNotifications];
最后,我处理这些通知如下:
-(voID)application:(UIApplication *)application dIDReceiveRemoteNotification:(NSDictionary *)userInfo{ CKNotification *note = [CKNotification notificationFromremoteNotificationDictionary:userInfo]; if (note.notificationType == CKNotificationTypequery) { CKqueryNotification *queryNote = (CKqueryNotification *)note; CKRecordID *recordID = [queryNote recordID]; [[NSNotificationCenter defaultCenter] postNotificationname:kCloudKitNewRecordFlightLog object:recordID]; }}
问题2:
为什么我此时不会收到任何通知?添加/删除,更新新记录时,我的所有代码都会运行并且我的应用程序会更新.但是,不会显示声音,徽章或横幅以通知用户.
问题3:
这是一种明智的方法,当收到云套件通知然后有本地通知发送消息到相关视图更新记录?
解决方法 >是的,你只需要设置一次.您可以查询订阅(使用fetchAllSubscriptionsWithCompletionHandler)以查看是否应该创建它.或者只是忽略错误. >那可能有用,或者你可以设置一个代表性的meganism. 总结以上是内存溢出为你收集整理的ios – CloudKit CKSubscription通知基础全部内容,希望文章能够帮你解决ios – CloudKit CKSubscription通知基础所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)