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

//检查数据库|| 复制数据库文件
    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"




posted @ 2011-11-01 17:38  痴人指路  阅读(197)  评论(0编辑  收藏  举报