Implement iCloud in CoreData applications after submitting, how to transfer old data

I plan to ship the CoreData application, but I'm not sure I represent the functionality of iCloud. This question arises after I beta test my application on iPhone, filling it with relevant data. Then I added iCloud functionality and started testing the iPad. I found that only the new record was synchronization between devices, these were preliminary steps:

  • Work with iPhone, fill in data, enable iCloud, launch work on a blank iPad.

But I had some strange problems, such as child entities tied to the wrong parent. Then I tried this.

  • Export application documents from iPhone and import into iPad

In this case, the data on both devices is the same, but I still could not synchronize the old data, while the new ones get full synchronization most of the time in seconds.

I understand that CoreData synchronization occurs with the exchange of transaction logs, so it would be obvious that the old data is not synchronized. But at the moment I’m asking if someone has already encountered this problem, which seems normal to me, or if I’m missing something, some settings or lines of code to make it work as expected.

+6
source share
1 answer

I don’t think you missed something. The main problem is that iCloud does not support a previously saved database. Something bothered me too. From document

https://developer.apple.com/library/ios/#releasenotes/DataManagement/RN-iCloudCoreData/_index.html

You should not post initial content with a pre-packaged database file. Instead, you should create default items in your code or use NSPersistentStoreCoordinator's migratePersistentStore: toURL: options: withType: error: method to transfer the pre-packaged database to the right place.

I have not tried to use the migratePersistentStore method: ... yet for my work, but the key fact is that the transfer of main data through iCloud through transaction logs depends on each transaction from the moment the database is born, it is tracked by the mechanism.

I would suggest that using migratePersistentStore: ... will result in a large number of allocations in the transaction.

+5
source

Source: https://habr.com/ru/post/909932/


All Articles