10

I'm using a CKFetchRecordChangesOperation with a CKFetchRecordsChangeToken to grab changes and it is telling me that the "AppDefaultZone does not support sync semantics".

Here is the offending code:

- (void)downloadServerChangesWithCompletionBlock:(void (^)(NSError *error))completionBlock
{
    // Prepare to fetch remote changes
    CKDatabase *database = [CKContainer defaultContainer].privateCloudDatabase;
    CKRecordZoneID *zoneID = [[CKRecordZoneID alloc] initWithZoneName:CKRecordZoneDefaultName ownerName:CKOwnerDefaultName];

    // Initialize fetch record changes operation
    CKFetchRecordChangesOperation *fetchRecordChangesOperation = [[CKFetchRecordChangesOperation alloc] initWithRecordZoneID:zoneID previousServerChangeToken:[self changeToken]];
    fetchRecordChangesOperation.recordChangedBlock = ^(CKRecord *record) {
        [self performRecordChange:record];
    };
    fetchRecordChangesOperation.recordWithIDWasDeletedBlock = ^(CKRecordID *recordID){
        [self performRecordDeletion:recordID];
    };
    fetchRecordChangesOperation.fetchRecordChangesCompletionBlock = ^(CKServerChangeToken *serverChangeToken, NSData *clientChangeTokenData, NSError *error) {
        if (error) {
            completionBlock(error);
        } else {
            [self setChangeToken:serverChangeToken];
            completionBlock(nil);
        }
    };

    // Perform the operation
    [database addOperation:fetchRecordChangesOperation];
}

And here is the error it is printing out

[PBCloudKitSyncManager] Error Downloading Data:
<CKError 0x157a2500: "Server Rejected Request" (15/2027);
server message = "AppDefaultZone does not support sync semantics";
uuid = [redacted];
container ID = "[redacted]">
János
  • 32,867
  • 38
  • 193
  • 353
Jonathan
  • 925
  • 6
  • 19

1 Answers1

2

I fixed the problem by switching to a custom zone. I create the zone when I initialize CloudKit and when I go to initialize the zoneID I use this:

CKRecordZoneID *zoneID = [[CKRecordZoneID alloc] initWithZoneName:@"Custom Zone Name" ownerName:userRecordName];

where userRecordName is the record name for the CKRecord I get for the user when I call this method in the Cloudkit initialization:

[CKContainer defaultContainer] fetchUserRecordIDWithCompletionHandler:^(CKRecordID *recordID, NSError *error) {
     if (recordID) {
         // Save the user record id
         [self saveUserRecordName:recordID.recordName];

          /...

      }
}];
Jonathan
  • 925
  • 6
  • 19
  • 2
    The documentation for CKRecordZoneID states: `To specify the current user, use the CKOwnerDefaultName constant. If you specify nil or an empty string for this parameter, this method throws an exception.` – Klaas Oct 25 '14 at 14:31
  • Does it mean that `CKFetchRecordChangesOperation` will not work in public database only in private? – János Dec 31 '14 at 13:17
  • @János the problem I was having actually dealt with the private database. So it looks to me like a CKFetchRecordChangesOperation will not work in the default zone of the public database or the private database. So to use the operation you have to create a custom zone and watch for changes in that custom zone. – Jonathan Jan 06 '15 at 22:57
  • 1
    @Jonathan, per your comment "CKFetchRecordChangesOperation will not work in the default zone of the public database". Can you create a custom zone in the public database ? – user2924482 May 22 '15 at 11:03
  • @user2924482 Yes, you can create a custom zone in the public database. That's what I ended up doing. – Jonathan May 22 '15 at 19:37
  • @Jonathan why didn't use CKFetchNotificationChangesOperation to use the default zone ? – user2924482 May 22 '15 at 20:28
  • how do you create custom zone in the public database? – user2924482 May 26 '15 at 03:19
  • 3
    "You cannot create custom zones in a public database." https://developer.apple.com/library/prerelease/ios/documentation/CloudKit/Reference/CKRecordZone_class/index.html – malhal Feb 10 '16 at 13:25
  • 1
    Terminating app due to uncaught exception 'CKException', reason: 'Zones cannot be created or modified in the public database' – malhal Feb 10 '16 at 19:32