I'm working on an old iOS app which has in app database i.e. pre populated database is provided to the app so that app can read(only read), now in updated version only information in table is updated(tables are same). when i test new data base i have to delete app from device to get new data otherwise i get old data.
So my question is that how to migrate from old data to new data if user update the application from App Store?
I've gone through this and this SO post but these post are about alter tables but i want to update only my records.
Edit:- If i change database file name while searching in document directory with new database file name, will it do the trick?Here is my code-
- (void) copyDatabase {
//Using NSFileManager we can perform many file system operations.
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
dbPath = [self getDBPath];
BOOL success = [fileManager fileExistsAtPath:dbPath];
if(!success) {
NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"mydb1.1"];
success = [fileManager copyItemAtPath:defaultDBPath toPath:dbPath error:&error];
if (!success)
NSAssert1(0, @"Failed to create writable database file with message '%@'.", [error localizedDescription]);
}
}
- (NSString *) getDBPath {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);
NSString *documentsDir = [paths objectAtIndex:0];
return [documentsDir stringByAppendingPathComponent:@"mydb1.1"];
}
"mydb1.1" is the new file name.