How to avoid fetching changes made by itself?

How to avoid fetching changes made by itself?

on iphone A, user saved a record into iCloud. for the next startup, when user fetchChanges,

why it still get the same record inserted earlier? how to avoid it?

Replies

You can't avoid this. Syncing relies on the change token handed to you when you fetch changes, and saving a new record to the cloud doesn't affect that token, so the next time you fetch changes, the cloud only knows you are current up to that token. You might be syncing from another device entirely, too.

You can 'roll your own' token by storing in the CKRecord a field with the NSDate value of 'now' each time you make a change or add a record and storing locally a value for 'now' each time you synch or make a change (including a synch). Then do a query for that field with an NSDate greater than the date last stored.

My personal experience is that using NSDate's to filter out changes made by myself is not entirely reliable, because sometimes devices may have slight differences in how the clocks are set, not to mention differences in how time is managed by iCloud. I'd rather use a kind of transaction ID value that marks the change as local. You can check against that ID and then ignore it if that make sense in the logic you are planning for your app.