我正在尝试设置一个 Cloudkit 订阅,每次创建特定记录类型的新记录时都会向我发送通知。我用来设置订阅的代码如下。
它正在一台设备上运行。如果我在另一台设备上创建新记录,它会收到通知。
但相同的代码在另一台设备上运行时会返回 Type 11 错误。这个相同的设备能够创建这种类型的记录并存储它。
我完全被难住了。任何关于正在发生的事情以及如何解决它的指针将不胜感激!
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"TRUEPREDICATE"];
CKSubscription *artisSubscription = [[CKSubscription alloc]
initWithRecordType:@"DummyRecordType"
predicate:predicate
options:CKSubscriptionOptionsFiresOnRecordCreation];
CKNotificationInfo *notificationInfo = [CKNotificationInfo new];
notificationInfo.alertLocalizationKey = @"how many dummies will I get.";
notificationInfo.shouldBadge = YES;
artisSubscription.notificationInfo = notificationInfo;
[self.publicDatabase saveSubscription:artisSubscription
completionHandler:^(CKSubscription *subscription, NSError *error) {
if (error)
{
NSLog(@"error %@ while saving subscription %@",error,artisSubscription) ;
}
else
{
NSLog(@"Successfully created subscription") ;
}
}];
此 NSLog 显示设备能够创建 DummyRecordType 类型的记录
2016-03-20 01:41:40.654 Successfully stored dummy record record <CKRecord: 0x14f662e40; recordType=DummyRecordType, recordID=AF6F246A-9CBA-412C-8B7D-441E47105DC3:(_defaultZone:__defaultOwner__), recordChangeTag=im0be2zp, values={
FirstName = "Sandra Boticelli";
}>
此 NSLog 显示设备无法为相同的记录类型 DummyRecordType 创建订阅
2016-03-20 01:41:48.053 error <CKError 0x14f643e80: "Unknown Item" (11/2003); server message = "did not find required record type: _sub_trigger_sub_0e58a7f4546c28b9d6f073bfa910e7f3"; uuid = E5CA48C1-8D46-47DD-8D0F-C486C2DA7D5D; container ID = "iCloud.com.apm.smartiothome.DoodleSend"> while saving subscription <CKSubscription: 0x14f57a2e0; ; Query Subscription: recordType=DummyRecordType, predicate=TRUEPREDICATE, subscriptionOptions=1, subscriptionID=FA20F835-DFB5-418A-BB51-462432BD4EFE, zoneID=(null)>