CKFetchRecordZoneChangesOptions fails along the way

Hi!

I am using CKFetchRecordZoneChangesOperation to fetch changes for a single zone at a time. fetchAllChanges is set to NO.

When pulling changes from a shared zone, with a NULL server change token (to fetch all objects from scratch), the download sometimes (25% of the time) fails along the way. Here's what I am seeing when downloading changes:

CKFetchRecordZoneChangesOperation token NULL

Got token A

Save local cache

CKFetchRecordZoneChangesOperation token A

Got token B

Save local cache

CKFetchRecordZoneChangesOperation token B


ERROR -> "Change Token Expired" (21/2026); server message = "client knowledge differs from server knowledge"


OR


ERROR -> "Internal Error" (1/1000); "Encountered an error fetching records", NSUnderlyingError = "<CKError 0x60001105bc90: \"Internal Error\" (1000/1013); \"Fetching asset failed\">";

Strangely, running CKFetchRecordZoneChangesOperation with Token B again after the failure works perfectly.

Anyone can shed some light on this strange behaviour? This happens on macOS as well as iOS.

Thanks in advance!

Replies

Hi,

I'm getting the same "client knowledge differs from server knowledge". How did you ever solve this problem?


Thanks.

I did some further digging and found my problem; if interested, see https://forums.developer.apple.com/thread/90794 for details.

Overview:

The corresponding error code is changeTokenExpired


Cause:

When this happens, it means that the change token you supplied to the operation is either too old or has expired.


Solution:

Retry the same operation by passing change token as nil, that way it would fetch all the zone changes from scratch.