What is clientChangeTokenData in CKModifyRecordsOperation?

I am working on CloudKit synchronization in my application (Small Data, All Devices model with a user zone in a private database).

CKModifyRecordsOperation contains a clientChangeTokenData property of type NSData , which is described in the documents as follows:

When you modify records from a fetch operation, specify the data token created by the client using this property to indicate which version of the last record was changed. Compare the data token that you put in the data token in the next record to confirm that the server successfully received the last request to change devices.

I don’t understand why I should worry, given that with every request I get a completion block that tells me if the server successfully received my request. Why do I need to manually compare this client token?

Specifies clientChangeTokenData to properly handle my usage example? I track local data changes and pop everything in the queue every time the data changes. Remote changes are tracked by subscribing to a zone.

If necessary, how can I correctly create this token, given that I have all the change records in CKModifyRecordsOperation ? (using my API for batch operations). What is the overall workflow here?

Thanks.

+10
source share
2 answers

You will only have a reason to check the token if you had local changes that you want to write to CloudKit, and you want to make sure that your changes are based on the latest version of the data in CloudKit.

You can also just ignore the token and save the data anyway. If the data has changed on average, you get a CloudKit error, and then you can handle it.

+3
source

This is not clear from the documents, so I assume that clientChangeTokenData is useful in case of sending a large record modification operation, for example, deleting 100 records. Then, say, your application sends a selection request in another operation with a set of query results (or selection of changes), which will be affected by modifications that either:

  1. starts and works simultaneously with the existing modification operation, which is not yet completed.
  2. starts before the server has finished processing the results of previous modifications (documents tend to refer to processing delay).

If the completion of the selection contains another clientChangeTokenData from the one that was sent with the change, then you know that it has not yet received (or completed processing?) The Change. In this situation, you can either give an error warning that the server needs more time, or automatically retry the selection after a while.

By the way, in my tests this token is for each device.

+3
source

All Articles