1

I've a published app synchronizing a Core Data with iCloud. I need to update the model adding two attributes and then populate these new fields.

I've tested lightweight migration locally and works fine, I can see the old data migrated into the new model scheme.

When I activate iCloud, old data saved in the ubiquity container doesn't sync with the new model schema. What is the expected behavior? Should I be able to sync data both on old and new model versions? How can I achieve it and test this situation?

I've read:

CoreData versioning and

Understanding Core Data iCloud Store Migration When Testing an iOS App Update

but, actually, I'm very confused.

Community
  • 1
  • 1
laucel
  • 509
  • 1
  • 5
  • 17
  • 2
    I found upgrading an iCloud store to be unreliable, and particularly when using WAL mode. The approach I take now is to check if the store needs to be upgraded when the app starts, and if so I then first migrate the store to a local store, then perform the upgrade and then migrate it back to iCloud. This seems to work reliably now but does require some interaction with the user as things can take a while and you need to ensure that the iCloud store gets removed completely and then replaced on all devices.... – Duncan Groenewald May 13 '15 at 00:12
  • I would like not to involve user interaction in this migration, but situations like http://stackoverflow.com/questions/27792667/icloud-core-data-model-schema-migration#comment48520244_27792667 creep me out – laucel May 13 '15 at 11:24
  • 1
    Exactly, see my point above re performing migrations on an iCloud store... If it is not 100% reliable it's not an option. I also provide a backup feature that migrates the existing store (iCloud or local) to another local file. The user then has the option of copying the backup file to iCloud to provide an additional backup copy and/or restoring the database from one of the backups. You can find more info on some of my other posts which have links to a sample app and code for some of this. – Duncan Groenewald May 14 '15 at 02:13

1 Answers1

4

What's supposed to happen is that iCloud data only syncs between devices that are using the same version of the data model. If you upgrade the app on one device but not on a second device, they won't sync changes until the second device also updates to the new model version.

If that's not what you're seeing, please add more details about the problem you're seeing.

Tom Harrington
  • 69,312
  • 10
  • 146
  • 170
  • thanks now it's clear. For testing purpose should I install on a device the app with the older model version and then on that the new app with the newer model version? If I am not mistaken, building the new app on the published one should not work – laucel May 12 '15 at 16:33
  • 1
    If you mean installing the app from Xcode when there's already an app store version on the phone, that should work. It's a pretty common method of testing the upgrade process for a new version of an app. – Tom Harrington May 12 '15 at 16:37
  • I meant that, but migration it's not working when I install the app from Xcode (new model) on the store version (old model),please see the second link in the question, thanks – laucel May 12 '15 at 16:43
  • I'm having the behavior you've described installing from Xcode the app version with containing the old model version and then installing the app containing the new model version, but not in the situation I've described in the previous comment – laucel May 12 '15 at 17:34