Search code examples
iosobjective-cswifticloudcloudkit

CKFetchRecordChangesOperation what is the returned clientChangeToken?


I am working on an app with CloudKit enabled and a local CoreData cache which syncs with iCloud using CloudKit. I am using the CKFetchRecordChangesOperation class to fetch new, changed and deleted records. The returned CKServerChangeToken is used for every consecutive fetch. CKModifyRecordsOperation is used to add and delete records.

If I add a record using CKModifyRecordsOperation the operation will return a new CKRecord. And if I then perform a new fetch using CKFetchRecordChangesOperation the newly added record is fetched again which is unnecessary. Does anyone know how to prevent this behaviour?

I know there is a property called clientChangeTokenData of type NSData on the CKModifyRecordsOperation however the clientChangeToken returned from CKFetchRecordChangesOperation is always nil for some reason.


Solution

  • Besides the previousServerChangeToken there is no other mechanism for controlling what should be returned by the CKFetchRecordChangesOperation. It will just return the changes. This will include the changes that you have made yourself.

    If that's a problem, then you could try using subscriptions instead. these will by default exclude the changes that are made by yourself.