在我的应用程序中,我使用了 sqlite DB。我将应用程序的 1.0 版本提交到应用商店。但在那之后,我对数据库进行了一些更改,例如插入一些新行。
然后提交了1.1版本的app。But i will not able to get updated DB because the old DB already exists in device.
我该如何解决这个问题?
如果我删除应用程序然后安装新版本的应用程序,那么我得到了更新的数据库。
//My code for copy of DB is as follow:
- (void)createEditableCopyOfDatabaseIfNeeded
{
// First, test for existence.
BOOL success;
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:@"xxx.sqlite"];
success = [fileManager fileExistsAtPath:writableDBPath];
if (success) return;
// The writable database does not exist, so copy the default to the appropriate location.
NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"xxx.sqlite"];
success = [fileManager copyItemAtPath:defaultDBPath toPath:writableDBPath error:&error];
if (!success) {
NSAssert1(0, @"Failed to create writable database file with message '%@'.", [error localizedDescription]);
}
}
我在 appDidFinishLaunching 方法中调用了这个方法。
当新版本可用时,如何在不删除应用程序的情况下获取更新的数据库