アプリケーションがこのディレクトリにファイルを書き込むディレクトリに対して、完全な読み取り/書き込みアクセス権を与える必要があります。私は、サンドボックスアプリケーションを使用してそれを読むと、アプリケーションを再起動した後にフォルダにアクセスするために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)
を与えることで、ここでのコードに基づいてそれを実装しようとしています?上記のコードに何か間違っています。