CloudKit参考订阅需要CKReferenceActionDeleteSelf参考吗?

时间:2015-11-17 18:40:36

标签: ios cloudkit cksubscription

我已根据父记录的引用字段为子记录更改创建了订阅。

当我创建子记录并使用 CKReferenceActionNone 引用设置子父级引用时,订阅不会生成推送通知。如果我使用 CKReferenceActionDeleteSelf 引用,则订阅按预期工作,在所有订阅的设备上生成推送通知。

我不想要级联删除。为什么我需要使用 CKReferenceActionDeleteSelf 引用来生成推送通知?

以下是代码:

// subscription registration
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"%K == %@", @"parent_ref", _parentRecordID];
CKSubscription *subscription = [[CKSubscription alloc] initWithRecordType:@"Child"
                                                                predicate:predicate
                                                                  options: CKSubscriptionOptionsFiresOnRecordCreation|CKSubscriptionOptionsFiresOnRecordUpdate|CKSubscriptionOptionsFiresOnRecordDeletion];
CKNotificationInfo *notificationInfo = [[CKNotificationInfo alloc] init];
notificationInfo.alertBody = @"Alert body";
notificationInfo.shouldBadge = YES;
notificationInfo.shouldSendContentAvailable = YES;
subscription.notificationInfo = notificationInfo;
[_db saveSubscription:subscription 
    completionHandler:^(CKSubscription *subscription, NSError *error) {
        // completes without error
}];

...

// child record construction
CKReference *parentRef = [[CKReference alloc] initWithRecordID:_parentRecordID 
                                                        action:CKReferenceActionNone];
CKRecord *childRecord = [[CKRecord alloc] initWithRecordType:@"Child"];
childRecord[@"parent_ref"] = parentRef;
[_db saveRecord:childRecord completionHandler:^(CKRecord *record, NSError *error) {
    // completes without error, but does NOT generate a push notification.
    // HOWEVER, if parentRef.action is CKReferenceActionDeleteSelf instead of 
    //      CKReferenceActionNone, then push notifications fire on other devices, 
    //      as expected.
}];

-saveRecord:完成但没有错误,但不生成推送通知。 但是,如果parentRef.action是CKReferenceActionDeleteSelf而不是CKReferenceActionNone,则按预期方式在其他设备上触发推送通知。

为什么会这样?

0 个答案:

没有答案