У меня есть изолированное приложение для 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];
}
}
}];