ylliX - Online Advertising Network

Quick tip: AppDefaultZone does not support sync semantics

If you just started playing with CloudKit, probably you will see that error trying to implement custom synchronization. Why need custom synchronization? Because receiving push message each time something changed in your cloud will be annoying. So probably you started with:

CKDatabase *database = [[CKContainer defaultContainer] privateCloudDatabase];
CKRecordZoneID *zoneID = [[CKRecordZoneID alloc] initWithZoneName:CKRecordZoneDefaultName ownerName:CKOwnerDefaultName];
CKFetchRecordChangesOperation *fetchRecordChangesOperation = [[CKFetchRecordChangesOperation alloc] initWithRecordZoneID:zoneID previousServerChangeToken:nil];
fetchRecordChangesOperation.fetchRecordChangesCompletionBlock = ^(CKServerChangeToken *serverChangeToken, NSData *clientChangeTokenData, NSError *error) {
    NSLog(@"fetchRecordChangesCompletionBlock %@", serverChangeToken);
    NSLog(@"fetchRecordChangesCompletionBlock %@", error);

and this is a place where you will see such error. Why this happens? Becouse you cannot fetch changed records for default zone. This applies both private and public cloud. So what to do? You need to create new zone before you will save anything to database:

CKDatabase *privateDatabase = [[CKContainer defaultContainer] privateCloudDatabase];
CKRecordZone *newZone = [[CKRecordZone alloc] initWithZoneName:@"ShareTestZone"];
[privateDatabase saveRecordZone:newZone completionHandler:^(CKRecordZone *zone, NSError *zoneError) {
    if (!zoneError) {
       NSLog(@"zone created");

After refreshing your cloud dashboard you will see your zone in “Private data” section. Now you can change zoneId to:

CKRecordZoneID *zoneID = [[CKRecordZoneID alloc] initWithZoneName:@"ShareTestZone" ownerName:CKOwnerDefaultName];

Of course you can use whatever name you want, this will also allow you to logically group records. Now in fetchRecordChangesCompletionBlock you should see:

fetchRecordChangesCompletionBlock <CKServerChangeToken: 0x7c17c770; data=AQAAAAAAAAADf/////////82R2EDHolICrHf6fPmTmm5>
fetchRecordChangesCompletionBlock (null)

And the second info means there is no error, and in first you have your CKServerChangeToken you need to save somewhere for next call.

Leave a Reply