1

I've created a subscription for child record changes, based on a reference field to a parent record.

When I create a child record and set the child's parent reference with a CKReferenceActionNone reference, the subscription does not generate a push notification. If I use a CKReferenceActionDeleteSelf reference, the subscription works as expected, generating push notifications on all subscribed devices.

I do not want want cascading deletes. Why do I need to use a CKReferenceActionDeleteSelf reference to generate push notifications?

Here is the code:

// 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.
}];

The -saveRecord: 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.

Why would this be?

4

0 回答 0