0

I am having an issue with my CoreData to iCloud synchronization with NSPersistentCloudKitContainer.

The synchronization works, but when i do a fresh install of the app there is an annoying delay of several seconds between app launch and the end of synchronization. I need to decide at launch whether to create new data entities or use the "old" data from iCloud.

I could live with the delay and wait for the sync to finish if there was a way to

a) determine at launch that there is data in iCloud to be synchronized and

b) get a notification when synchronization is finally done

Does anyone know of a solution to achieve this? Setting NSPersistentStoreRemoteChangeNotificationPostOptionKey does not help much, as it is fired several times during sync and does not give any status information.

Michael
  • 182
  • 1
  • 9

1 Answers1

4

At the risk of providing you the most unhelpful answer possible, I don't think it is possible and, even if it is, I think you are battling against the philosophy of NSPersistentCloudKitContainer.

With NSPersistentCloudKitContainer, you should assume that synchronisation happens at irregular, erratic intervals or not at all. It is supposed to operate seamlessly, in the background, with nothing for you to worry about. You shouldn't try to speculate in your code when it happens or if it happens.

It is very similar to taking a photo on your iPhone and then it taking several seconds for that photo to appear on your iMac. The iCloud sync decides if and when that sync will take place.

I know this is not helpful, but I thought you should be aware of this perspective.

Ch Ryder
  • 360
  • 3
  • 10