apple / sample-cloudkit-sync-engine

MIT License
172 stars 13 forks source link

Records saved to the default zone are never synced down #14

Closed JackMorris closed 5 months ago

JackMorris commented 5 months ago

I'm trying to integrate CKSyncEngine, however when saving records to the default zone I never receive .fetchedRecordZoneChanges events for them (on subsequent installs, or separate devices).

For example, if I do the following:

let zoneID = CKRecordZone.ID(zoneName: "MyZone")
syncEngine.state.add(
  pendingDatabaseChanges: [
    .saveZone(CKRecordZone(zoneID: zoneID))
  ]
)
syncEngine.state.add(
  pendingRecordZoneChanges: [
    .saveRecord(CKRecord.ID(recordName: "MyRecord", zoneID: zoneID))
  ]
)

A batch of changes is requested, and the resulting record is up-synced correctly. On fresh installs, or a different device, I get both .fetchedDatabaseChanges and .fetchedRecordZoneChanges events, as expected.

However, with the following (instead persisting the record to the default zone):

syncEngine.state.add(
  pendingRecordZoneChanges: [
    .saveRecord(CKRecord.ID(recordName: "MyRecord"))
  ]
)

A batch of changes is requested and the resulting record is up-synced to the default zone correctly, as expected (verified with the cloud console). However on fresh installs, or a different device, I get neither a .fetchedDatabaseChanges event (expected I guess, since I don't need to "create" the default zone?), or .fetchedRecordZoneChanges events.

Is using the default zone supported with CKSyncEngine?

malhal commented 5 months ago

Default zone does not support fetching changes

The disadvantage of using the default zone for storing records is that it doesn’t have any special capabilities. You can’t save a group of records to iCloud atomically in the default zone. Similarly, you can’t use a CKFetchRecordChangesOperation object on records in the default zone.

ref: https://developer.apple.com/documentation/cloudkit/ckrecordzone/1514919-defaultrecordzone

JackMorris commented 5 months ago

Noted, thank you!

I feel like this should be documented at the CKSyncEngine level (since the default zone is effectively not supported with CKSyncEngine), but this issue is probably not the best place for that. Will close.

timimahoney commented 5 months ago

Filed feedback FB13723643.