Trong ứng dụng của tôi, tôi đã sử dụng DB sqlite. Tôi đã gửi phiên bản 1.0 của ứng dụng tới cửa hàng ứng dụng. Nhưng sau đó tôi đã thực hiện một số thay đổi vào DB như Chèn một số hàng mới.Sao chép cơ sở dữ liệu đã cập nhật vào thiết bị trong ios sdk
Sau đó, gửi phiên bản 1.1 của ứng dụng. But i will not able to get updated DB because the old DB already exists in device.
Làm cách nào tôi có thể giải quyết vấn đề này?
Nếu tôi xóa ứng dụng & thì hãy cài đặt phiên bản ứng dụng mới, sau đó tôi đã cập nhật DB.
//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]);
}
}
Tôi gọi phương thức này trong phương pháp appDidFinishLaunching.
Làm thế nào tôi có thể được cập nhật DB mà không xóa các ứng dụng khi phiên bản mới có sẵn
Cảm ơn rất nhiều! Wow, thật tuyệt vời khi làm điều này rất dễ dàng. – AtWork