I know how to create sqlite database, inserting data into it, deleting row into it etc. through iPhone development, but i am trying to remove the entire database itself programmatically, but not getting any helps. Please someone guide me how to delete/remove the entire sqlite database itself from device thru code.
Thank you!
If your db is in Documents you can try:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"youdb.db"];
if([[NSFileManager defaultManager] fileExistsAtPath:filePath]){
[[NSFileManager defaultManager] removeItemAtPath:filePath error:nil];
}
Try
NSError *err;
NSFileManager *fm = [NSFileManager defaultManager];
err = nil;
NSString *deleteFileName = [NSString stringWithFormat:@"%@/FileName",[[NSBundle mainBundle] resourcePath]];
NSURL *url = [NSURL fileURLWithPath:deleteFileName];
[fm removeItemAtPath:[url path] error:&err];
if(err)
{
NSLog(@"File Manager: %@ %d %@", [err domain], [err code], [[err userInfo] description]);
}
else
{
NSLog(@"File %@ deleted.",fileName);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With