CloudKit Sync Complete Event/Notification

How does one know when the CloudKit data in a CoreData+CloudKit (NSPersistentCloudKitContainer) has been fully synchronized. UseCase would be a user starts the App on a second device, user deletes then reinstalls the App, another User accepts a share and the share needs to sync.

Is the containerEventChanged Notification for 'import success' the definitive event?

CoreData: CloudKit: CoreData+CloudKit: -[NSCloudKitMirroringDelegate _finishedRequest:withResult:](3403): Finished request: <NSCloudKitMirroringImportRequest: 0x600002345d10> 729A742A-7F3B-42F1-B04C-72705D41FFEF with result: <NSCloudKitMirroringResult: 0x600000c4edc0> storeIdentifier: 79FA5848-A135-41B1-A36A-09F2F914D23D success: 1 madeChanges: 0 error: (null)

As the sync could be time-consuming, is there a way to identify a single CloudKit record?

Accepted Reply

https://developer.apple.com/documentation/coredata/nspersistentcloudkitcontainer/event

When you get a successful .import event your device is "current" with whats in iCloud. You can then use a fetch request to identify / check for interesting data.

Note that "current" here is caught-up-to the iCloud server, it doesn't imply anything about the state of other devices.

  • This event is guaranteed on App startup, either with 'succeeded' or 'error', on startup for every 'storeIdentifier'? Even if no changes have occurred between App startups? That is, container.loadPersistentStores(...) for an NSPersistentCloudKitContainer produces these events?

  • And, why are there multiple .import notifications for the same store on App start (that calls loadPersistentStores(...)?

Add a Comment

Replies

https://developer.apple.com/documentation/coredata/nspersistentcloudkitcontainer/event

When you get a successful .import event your device is "current" with whats in iCloud. You can then use a fetch request to identify / check for interesting data.

Note that "current" here is caught-up-to the iCloud server, it doesn't imply anything about the state of other devices.

  • This event is guaranteed on App startup, either with 'succeeded' or 'error', on startup for every 'storeIdentifier'? Even if no changes have occurred between App startups? That is, container.loadPersistentStores(...) for an NSPersistentCloudKitContainer produces these events?

  • And, why are there multiple .import notifications for the same store on App start (that calls loadPersistentStores(...)?

Add a Comment