그런 다음 문서 디렉토리에서 사용할 수 있습니다, 그것은 doc 디렉토리에 DB를 복사합니다
- (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"];
}
을보십시오.