我对商店的应用程序,它指向文档directory.Here的旧代码的appname.sqlite文件:预先填充应用程序包中的sqlite文件。现有用户更新后会发生什么?
NSURL *storeURL = [[self applicationDocumentsDirectory]URLByAppendingPathComponent:@"MyApp.sqlite"];
NSError *error = nil;
_persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:@{NSMigratePersistentStoresAutomaticallyOption : @YES,NSInferMappingModelAutomaticallyOption : @YES}; error:&error]) {
abort();
}
我现在想给更新。这一新功能是一个预充式.sqlite数据库,其中有在bundle.See以下
NSURL *storeURL = [NSURL fileURLWithPath: [[NSBundle mainBundle] pathForResource:@"MyNewPrefilled" ofType:@"sqlite"]];
它的工作确定对新安装的app.But会发生什么谁已经登录,并有一个用户很多保存在数据库中的数据(应用程序目录中的旧sqlite)?我会失去它,因为我现在指向应用程序包(MyNewPrefilled.sqlite)中的.sqlite,而不是应用程序目录中的.sqlite。我怎样才能从旧版doc目录的sqlite文件中将旧数据恢复到捆绑中的新数据?我使用代码数据迁移(涉及数据模型中的版本号),当我更新数据模型时,它可以正常工作。
是要复制静态数据的数据吗?或者用户会改变它? – Mundi 2015-02-12 21:20:20
请注意,包中的文件是只读的。 – 2015-02-13 01:22:31