In the past, I released my application with a pre-installed database, so the user did not need to update it the first time it started. There was some code that I found in another SO question (sorry, I no longer have a link) that I added to my App Delegate persistentStoreCoordinator method:
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator { NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"db.sqlite"]; if (![[NSFileManager defaultManager] fileExistsAtPath:[storeURL path]]) { NSURL *preloadURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"db" ofType:@"sqlite"]]; NSError* err = nil; if (![[NSFileManager defaultManager] copyItemAtURL:preloadURL toURL:storeURL error:&err]) { NSLog (@"Error - Could not preload database."); } }
When I try to do this in iOS 7, I get no errors, but the database is empty (even if the database in my mainBundle has all the information I expect). I noticed that there are more database files in the applicationDocumentsDirectory (.sqlite-shm file and .sqlite-wal file). Do I need to do something with these files? Or is it already impossible to have a preloaded database ship with the application?
EDIT: I tried adding code to copy the new .sqlite-shm and .sqlite-wal files, but that doesn't help.
source share