I am making a new version of an app that upgrades an SQLite database from the old app version (no Core Data, no iCloud) to a new version with Core Data and iCloud. My app has some functionality to pull the data out of SQLite and add it to Core Data.
Here's the issue I'm having:
I can put a big warning in the new version's release notes about only upgrading one instance of the app and installing fresh on other devices, but some people aren't going to notice that.
Is there a programmatic way to prevent data duplication with multiple devices upgrading to Core Data/iCloud? I thought about adding a flag to iCloud key/value sync, but that data may not make it to the 2nd device in time before it does the database upgrade.
Any ideas? Thanks in advance.
iOS 7, Xcode 5.1.1
Using a flag in the ubiquitous KV store will work for detecting if data has been seeded. However, depending on how your app is setup you may still encounter duplicate data. For example, if the user can enable/disable iCloud and as part of that merge there data between iCloud and the local storage.
As frustrating as it can be it is generally better to add logic to detect and remove duplicate data. For that you will often need some additional information (eg. a last updated field). The key is to that the de-duplication is consistent across devices (eg. the same duplicate is always removed).
Based on past experience I would also be wary of using the ubiquitous KV store. It can take a long time to become synchronised. Instead I would recommend storing a file in iCloud with a unique identifier for each synchronised device. In that way you can tell if any data is present and if your device has previously synchronised with the iCloud data.
I have an iCloud stack (I use it in my own apps) which demonstrates basic de-duplication and a file based check that you can checkout on GitHub at https://github.com/IainMcManus/iOSCoreLibrary
There is more info on the file based check at http://iaintheindie.com/2014/06/14/icloud-core-data-part-2/