Try
- (void)copyDatabaseIfNeeded
{
BOOL success;
NSFileManager *fileManager = [NSFileManager defaultManager];
success = [fileManager fileExistsAtPath:[self getDBPath]];
if(success)
{
return;// If exists, then do nothing.
}
//Get DB from bundle & copy it to the doc dirctory.
NSString *databasePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"DB.sqlite"];
[fileManager copyItemAtPath:databasePath toPath:[self getDBPath] error:nil];
}
//Check DB in doc directory.
- (NSString *)getDBPath
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);
NSString *documentsDir = [paths objectAtIndex:0];
return [documentsDir stringByAppendingPathComponent:@"DB.sqlite"];
}
It will copy your DB in doc directory, then you can used it from doc directory.