Reputation: 43
I have a problem with the sqlite database. In my app i read an external db that I copy inside the iphone. It works!! Now I modified the database and I Have to replace it inside the iphone. I deleted the database from project and i put the new one (same name), then I start the simulator (or the iphone) and the app use again the old database. This is the code i use for copy the database:
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *appDBPath = [documentsDirectory stringByAppendingPathComponent:@"On4h.db"];
NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"On4h.db"];
success = [fileManager fileExistsAtPath:appDBPath];
if (success) {
return;
}
success = [fileManager copyItemAtPath:defaultDBPath toPath:appDBPath error:&error];
if (!success) {
NSAssert1(0, @"Failed to create writable database file with message '%@'.", [error localizedDescription]);
}
How it's possible to replace the database with another with the same name? How its possible that now the iphone read again the old one?
Thanks!!
Upvotes: 2
Views: 524
Reputation: 7207
To change the database you need to do the below..
Open Preferences
Go to location Tab and click on the arrow indicating.
Application Support -> iPhone Simulator -> 7.1 (your simulator version) -> Applications -> Find out your project -> Library -> Caches
on the above location you will found your old database. Now replace it with new one.
NOTE: Above process is for the iPhone/iPad simulator only
. For iPhone/ iPad devices you need to delete and reinstall the app.
Upvotes: 2