5

I building a iOS app using cloudKit. I'm trying to make a batch fetch of the data in cloudKit getting the deltas between the device and cloudKit but it seems like CKFetchRecordChangesOperation doesn't work in public database. Does my only option option is CKQuery to fetch my data ? for example:

 CKContainer *container = [CKContainer containerWithIdentifier:containerID];
    CKDatabase *publicDatabase = [container publicCloudDatabase];
    CKQuery *query = [[CKQuery alloc] initWithRecordType:recordType
                                               predicate:[NSPredicate predicateWithFormat:@"TRUEPREDICATE"]];
     CKQueryOperation *queryOp = [[CKQueryOperation alloc] initWithQuery:query];
    queryOp.desiredKeys = @[@"record.recordID.recordName"];
    queryOp.recordFetchedBlock = ^(CKRecord *record)
    {
        // do something...
    };

     queryOp.queryCompletionBlock = ^(CKQueryCursor *cursor, NSError *error)
    {
        // do something else...
    };

    queryOp.resultsLimit = CKQueryOperationMaximumResults;
    [publicDatabase addOperation:queryOp];

I'll really appreciate your help.

János
  • 32,867
  • 38
  • 193
  • 353
user2924482
  • 8,380
  • 23
  • 89
  • 173
  • if I good understand `CKFetchRecordChangesOperation` will work only in **private database** on a custom zone. `CKFetchNotificationChangesOperation` works on public database too. – János May 22 '15 at 15:26
  • @János can you post a example ? – user2924482 May 22 '15 at 18:49
  • here I shared code how to use `CKFetchNotificationChangesOperation`: http://stackoverflow.com/questions/30213261/ckfetchnotificationchangesoperation-cant-fetch-notification – János May 22 '15 at 18:53
  • @János do you have objective-C version? – user2924482 May 22 '15 at 18:56

1 Answers1

3

The apple documentation for CKFetchRecordChangesOperation states:

recordZoneID : The zone containing the records you want to fetch. The zone can be a custom zone. Syncing the default zone is not supported.

This means that it will not work on the public database since than only supports the default zone.

The correct way to achieve the same functionality would be by creating subscriptions for the data you need and retrieve that data using the CKFetchNotificationChangesOperation. Of course you could also just execute some CKQuery commands, but then you would probably often fetch data or execute queries that you don't need.

Edwin Vermeer
  • 13,017
  • 2
  • 34
  • 58
  • Note that the last sentence is missing from the OS X version of the class documentation in XCode 6.4. – Mojo66 Jul 28 '15 at 14:12
  • CKFetchNotificationChanges is useless for the OP because its not per device, its per account. – malhal Feb 11 '16 at 00:09