我在iOS應用程序中使用一個名爲testSqlite.sqlite的sqlite數據庫。我想將它複製到應用程序文件夾。但該文件不會複製到所需的位置。我也添加了我的源代碼。請幫助如何在運行時將數據庫從主包複製到應用程序文件夾?
NSString *docsDir;
NSArray *dirPaths;
dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = dirPaths [0];
NSString *backupPath = [[NSBundle mainBundle] pathForResource:@"testSqlite" ofType:@"sqlite"];
NSLog(@"backup is %@ ",backupPath);
if (![[NSFileManager defaultManager] fileExistsAtPath: docsDir]) {
if (backupPath) {
BOOL copiedBackup = [[NSFileManager defaultManager] copyItemAtPath:backupPath toPath:docsDir error:nil];
if (!copiedBackup) {
// copying backup db failed, bail
NSLog(@"Copying backup db failed");
}
else
NSLog(@"\n\ndatabase created");
}
}
請分享NSLog輸出 – freshking 2014-09-13 12:32:27