2
번들에서 사용자 문서로 데이터베이스 파일을 복사하려고합니다.코코아 오류가있는 copyItemAtPath를 사용하여 데이터베이스 파일을 복사 할 수 없습니다.
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 message : '
작업을 완료 할 수 없습니다. (코코아 오류 4). '
감사 인사.
I는 (YES, NSDocumentationDirectory, NSUserDomainMask) NSArray를 경로 * = NSSearchPathForDirectoriesInDomains의 변화; ~ NSArray * paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES); 및 모든 것이 좋습니다. 감사. – vic