2
문서 기반 Mac 응용 프로그램을 샌드 박스 처리했습니다. 내 문서는 사용자 컴퓨터에 이미지를 통합합니다. 내 문서에서 사용 된 이미지에 문서 범위의 책갈피를 저장하여 문서를 닫았다가 다시 열 때 이미지에 액세스 할 수있게하려고합니다.새 문서에 저장하기 위해 문서 유효 범위가 지정된 책갈피는 어떻게 만듭니 까?
//path is path to an image
//for a new document docUrl is set to the location where we will save our document
NSURL * pathUrl = [NSURL fileURLWithPath:path];
NSError * error;
NSData * pathBookmarkData = [pathUrl bookmarkDataWithOptions:
(NSURLBookmarkCreationWithSecurityScope
| NSURLBookmarkCreationSecurityScopeAllowOnlyReadAccess)
includingResourceValuesForKeys:[NSArray arrayWithObject:NSURLPathKey]
relativeToURL:docUrl error:&error];
이 다음과 같은 오류가 발생합니다 :
Error Domain=NSCocoaErrorDomain Code=260 "The file “Untitled.mydocext” couldn’t be opened because there is no such file." (Collection URL points to a file that doesn't exist) UserInfo=0x608000070800 {NSURL=file:///Users/myname/Pictures/Untitled.mydocext, NSDebugDescription=Collection URL points to a file that doesn't exist}
가 어떻게 새 문서에 저장되는 문서의 범위 북마크를 만들려면 어떻게해야합니까 여기
내가 책갈피를 만드는 방법입니까?
NSArray* fileTypes = [[NSArray alloc] initWithObjects:@"png", @"jpg", @"jpeg", @"bmp", @"gif", @"tif", @"tiff", @"PNG", @"JPG", @"JPEG", @"BMP", @"GIF", @"TIF", @"TIFF", nil];
NSOpenPanel *panel;
panel = [NSOpenPanel openPanel];
[panel setTitle:@"Select Photos"];
[panel setFloatingPanel:YES];
[panel setCanChooseDirectories:YES];
[panel setCanChooseFiles:YES];
[panel setAllowsMultipleSelection:YES];
[panel setAllowedFileTypes:fileTypes];
[panel beginWithCompletionHandler:^(NSInteger result){
if (result == NSFileHandlingPanelOKButton) {
NSMutableArray * pathsArray = [[NSMutableArray alloc] init];
NSArray * urlArray = [panel URLs];
for (NSURL * url in urlArray) {
//this is how I get path to image, assume I am not selecting directories
NSString * path = [url path];
}
}
}];
어떻게 '경로'를 얻었습니까? 선호되는 방법은 NSOpenPanel을 사용하여 보안 유효 URL을 얻거나 사용자가 앱에 이미지를 드롭하는 것입니다. –
사용자가 내 문서를 처음 저장하려고 시도 할 때까지 보안 범위가 지정된 책갈피를 가져 오는 것을 지연합니다. 이 때 문서를 저장할 위치를 얻고 relativeHRL을 bookmarkDataWithOptions : includeResourceValuesForKeys : relativeToURL : error : 함수를 사용하여 문서 범위의 책갈피를 얻습니다. – AmaltasCoder
@AmaltasCoder이 문제를 해결해 봤습니까? 나는 똑같은 일을하려하지만 OSX의 여러 가지 버그로 인해 문서 범위의 책갈피가있는 문서를 올바르게/안정적으로 저장할 수 없습니다. –