iCloud Core Data Model Schema Migration

蓝咒 提交于 2019-12-11 11:35:11

问题


Acording to Apple's Document, The lightweight migration for core data connected with iCloud can be performed automatically. And another documents from Apple says that:

If you migrate a persistent store configured with a NSPersistentStoreUbiquitousContentNameKey option to a new model version, the store’s history of changes originating from the current device will also be migrated and then merged with any other devices configured with that new model version. Any changes from stores using the new version are also merged in.

Existing changes can not, however, be migrated to a new model version if the migration is performed using a custom mapping model.

I could change my app to use iCloud, and I could migrate(manual) local database into ubiquity one successfully. So first core data with iCloud doesn't show any problems.

However, when I added new model version, The migrated store contains nothing. It is supposed to be contains migrated content that is created with older version of model. the store’s history of changes seems to be ignored for some reason.

As a result, Testers who installed new version of the app loses content which created with earlier version. There were no logs or errors.

When I tried same initializing process to store without NSPersistentStoreUbiquitousContentNameKey option(local store), everything were fine. All content are migrated and contained by new store correctly.

And the second documents says:

Existing changes can not, however, be migrated to a new model version if the migration is performed using a custom mapping model.

I think that My needs can be match this case. I have also custom mapping models. But I don't know the place to trigger.

My store options are very typical, not so special:

{
    NSInferMappingModelAutomaticallyOption = 1;
    NSMigratePersistentStoresAutomaticallyOption = 1;
    NSPersistentStoreUbiquitousContentNameKey = "moment-cloud";
    NSPersistentStoreUbiquitousContentURLKey = Logs;
}

Store URL is created as:

NSURL* docURL = [fileManager URLsForDirectory: NSDocumentDirectory inDomains: NSUserDomainMask].firstObject;
return [docURL URLByAppendingPathComponent: kFileNameDatabaseForUbiquitous];

来源:https://stackoverflow.com/questions/27792667/icloud-core-data-model-schema-migration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!