2
我想從數據包複製數據庫文件到用戶文檔。無法複製數據庫文件使用copyItemAtPath與可可錯誤4
我的代碼如下:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [paths objectAtIndex:0];
NSString *userPath = [documentsDir stringByAppendingPathComponent:@"db.sql"];
NSString *srcPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"db.sql"];
NSFileManager *fileManager = [NSFileManager defaultManager];
NSLog(@"Bundle database exists: %i",[fileManager fileExistsAtPath:srcPath]);
NSLog(@"User Document folder database exists: %i",[fileManager fileExistsAtPath:userPath]);
BOOL find = [fileManager fileExistsAtPath:userPath];
BOOL copySuccess = FALSE;
NSError *error;
if (!find) {
NSLog(@"don't have writable copy, need to create one");
copySuccess = [fileManager copyItemAtPath:srcPath toPath:userPath error:&error];
}
if (!copySuccess) {
NSLog(@"Failed with message: '%@'.",[error localizedDescription]);
}
,結果總是說:
捆綁數據庫中存在:1個用戶文檔文件夾數據庫中存在:0
沒有寫副本,需要創建一個Failed with消息:'
操作無法完成。 (可可錯誤4)'。
請建議,謝謝。
我改變的NSArray *路徑= NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory,NSUserDomainMask,YES); 至 NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES); 和一切都很好。謝謝。 – vic