我對商店的應用程序,它指向文檔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