응용 프로그램이이 디렉토리에 파일을 쓰는 디렉토리에 대한 전체 읽기/쓰기 권한을 부여해야합니다. 나는 샌드 박스 응용 프로그램을 사용하여 응용 프로그램을 다시 실행 한 후 Enable Security-Scoped Bookmark and URL Access 폴더에 액세스해야한다고 읽었습니다. 디렉토리의 보안 범위가 지정된 책갈피
그래서 나는 약간의 수정 What is the correct way to handle stale NSURL bookmarks? NSOpenPanel* openDlg = [NSOpenPanel openPanel];
[openDlg setCanChooseDirectories:YES];
[openDlg setCanCreateDirectories:YES];
[openDlg setAllowsMultipleSelection:FALSE];
if ([openDlg runModal] == NSOKButton)
{
NSArray *files = [openDlg URLs];
NSString* dirPath =[[files objectAtIndex:0] path];// absoluteString];
BOOL isDirectory;
NSFileManager* manager = [NSFileManager defaultManager];
NSString *Dir = [dirPath stringByAppendingPathComponent:@"ScreenCaptures"];
if (![manager fileExistsAtPath:Dir isDirectory:&isDirectory] || !isDirectory)
{
NSError *error = nil;
[manager createDirectoryAtPath:Dir
withIntermediateDirectories:NO
attributes:nil
error:&error];
if (error)
NSLog(@"Error creating directory snap path: %@", [error localizedDescription]);
}
NSURL *url = [NSURL URLWithString:[Dir stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSData *bookmark = nil;
NSError *error = nil;
bookmark = [url bookmarkDataWithOptions:NSURLBookmarkCreationWithSecurityScope
includingResourceValuesForKeys:nil
relativeToURL:nil // Make it app-scoped
error:&error];
if (error) {
NSLog(@"Error creating bookmark for URL (%@): %@", url, error);
[NSApp presentError:error];
}
NSLog(@"bookmark: %@", bookmark);
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setObject:bookmark forKey:@"bookmark"];
}
그러나 위의 코드는 나에게 문제가 될 수 무엇 오류
016-08-20 02:19:53.390 FileAccess[635:85753] modalSession has been exited prematurely - check for a reentrant call to endModalSession:
2016-08-20 02:19:59.979 FileAccess[635:85753] Error creating bookmark for URL (/Users/development/Documents/c/ScreenCaptures): Error Domain=NSCocoaErrorDomain Code=262 "Scoped bookmarks can only be made with file URLs" UserInfo={NSURL=/Users/development/Documents/c/ScreenCaptures, NSDebugDescription=Scoped bookmarks can only be made with file URLs}
2016-08-20 02:20:00.021 FileAccess[635:85753] CFURLCopyResourcePropertyForKey failed because it was passed an URL which has no scheme
2016-08-20 02:20:04.967 FileAccess[635:85753] bookmark: (null)
을주는 여기에 코드를 기반으로 그것을 구현하기 위해 노력하고 있어요? 위의 코드에 잘못된 것이 있습니다.