Monday, 19 August 2013

Failed to create writable database

Failed to create writable database

I stored some images in my server. And try to get this images from JSON
URL and store to local database then try to access. But the images are not
storing to database. Im getting this error: Failed to create writable
database file with message 'The operation couldn't be completed. (Cocoa
error 516.)'.
code:
- (void)viewDidLoad
{
NSFileManager *fileMgr = [NSFileManager defaultManager];
NSError *err;
NSString *bundlePath = [[NSBundle mainBundle]
pathForResource:@"db1" ofType:@"sqlite"];
NSArray *paths =
NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,
YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
//NSLog(@"docs dir is %@", documentsDirectory);
NSString *appFile = [documentsDirectory
stringByAppendingPathComponent:@"db1.sqlite"];
// [fileMgr copyItemAtPath:bundlePath toPath:appFile error:&err];
BOOL success = [fileMgr copyItemAtPath:bundlePath toPath:appFile
error:&err];
if (success) {
NSLog(@"success");
}else{
NSLog(@"Failed to create writable database file with message
'%@'.", [err localizedDescription]);
}
NSURL *URL = [NSURL
URLWithString:@"http://myserver.net/projects/mobile/jsonstring.php"];
NSError *error;
NSString *stringFromFileAtURL = [[NSString alloc]
initWithContentsOfURL:URL
encoding:NSUTF8StringEncoding
error:&error];
NSString *path = [documentsDirectory
stringByAppendingPathComponent:@"db1.sqlite"];
NSArray *userData = [stringFromFileAtURL JSONValue];
[stringFromFileAtURL release];
}

No comments:

Post a Comment