Reputation: 311
i use sqlite database on my iphone app and
i need to update this database from the internet from my server
how i can download the new database and delete the old database
and recopy the new database to document directory
Upvotes: 2
Views: 2126
Reputation: 366
Here is the full code
//replacing the db that I have emailed from app.
-(void)handleOpenURL:(NSURL *)url {
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *txtPath = [documentsDirectory stringByAppendingPathComponent:@"/DemoApp.sqlite"];
NSURL *newUrl = [[NSURL alloc] initWithString:
[txtPath stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]];
if ([fileManager fileExistsAtPath:txtPath] == NO) {
[fileManager copyItemAtURL:url toURL:newUrl error:&error];
}
else if ([fileManager fileExistsAtPath:txtPath] == YES) {
[fileManager removeItemAtPath:txtPath error:&error];
[fileManager copyItemAtURL:url toURL:newUrl error:&error];
}
}
Hope this helps
Upvotes: 0
Reputation: 9593
Upvotes: 5