检查数据库|| 复制数据库文件

//检查数据库|| 复制数据库文件
    NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *folderPath = [searchPaths objectAtIndex:0];
NSString *dbfilePath = [folderPath stringByAppendingPathComponent:DB_FILE_NAME];
if (![[NSFileManager defaultManager] fileExistsAtPath:dbfilePath]) {
//don't find db, need to copy
NSString *backDbPath = [[NSBundle mainBundle] pathForResource:DB_SOURCE_NAME ofType:DB_SOURCE_TYPE];
if (!backDbPath) {
NSLog(@"cannot find backup db to copy, bail");
} else {
BOOL copyBackDB = [[NSFileManager defaultManager] copyItemAtPath:backDbPath toPath:dbfilePath error:nil];
if (!copyBackDB) {
NSLog(@"copying backup db failed, bail");
}
}
}
#define DB_FILE_NAME @"gtalk.db"
#define DB_SOURCE_NAME @"gtalk"
#define DB_SOURCE_TYPE @"db"




原文地址:https://www.cnblogs.com/ligun123/p/2232048.html