我今天一直在和CKSubscription闲逛。我对此有几个疑问。
我的订阅方式如下:
-(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:
在接收云工具包通知时,让本地通知向相关视图发送消息以更新记录,这是一种明智的方法吗?
发布于 2014-11-12 14:57:38
https://stackoverflow.com/questions/26889786
复制相似问题