Reuse existing Core Data store from one iPhone app to another
Is there a way of using an existing core-data store from one app in a different 开发者_JAVA百科one, published by the same person and with the same com.company.* identifier?
The use case is to allow users who are upgrading from lite to pro version to still have all the data they had generated in the lite version once they launch the free version. Is this at all possible?
I would like to avoid using the pasteboard or url, which seem like a lot of hackery to me. Ideally I would just be hooking to the existing core data and sharing it between apps.
Your best bet would be to transfer the entire CoreData database from the older app to the newer one, using whatever mechanism works best - I think the pasteboard has a way of sharing whole files.
You have to transfer the file somehow since one app is not allowed to look into anothers application space.
You may want to check into iOS5 iCloud support as a mechanism to transfer files between apps as well, we can't answer questions about that on StackOverflow yet as iOS5 API features are still under NDA.
You coul register a url scheme for the old app and register a file type for the new app. The url is opened by the new app, the old app exports the data into a file / folder with the extension registered by the new app. The old app then "opens" the exported file using the documen manager and the new app is then called to open the file and can import it.
Wherever you have your NSPersistentStoreCoordinator class
Change:
if (![persistentStoreCoordinator_ addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) {
To:
if (![persistentStoreCoordinator_ addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES],NSMigratePersistentStoresAutomaticallyOption, [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil] error:&error])
Setting the options up this way tells the current build to use the existing data store and migrate the changes(if any) into the new version of the data store you created. I think this would work with what your attempting, same as if you changed the There is info in the Apple Core Data Documentation with a more detailed explanation.
You can set your app up within the store such that a lite
version and pro
version appear as different versions of the same app. When the user upgrades, the newer version is installed in the same logical directory as the old version and has access to the old versions data files.
精彩评论