"Scoped bookmarks can only be made with file URLs"
This isn’t referring to file vs directories, it means a URL with the
file
scheme (
file:///some/path
). You need to look at how
openPanelFileURL
is being created. Honestly, I don’t understand what the code you’ve posted is trying to do, and it doesn’t help that you haven’t shown where
urlString
comes from.
Most folks get a file URL straight from the open panel’s
URL
property (or
URLs
property, if you want to support multiple selection), and I
strongly recommend you do that in this case.
Here’s a simple example:
NSOpenPanel * panel;
panel = [NSOpenPanel openPanel];
panel.canChooseDirectories = YES;
panel.allowsMultipleSelection = NO;
panel.canChooseFiles = NO;
[panel beginSheetModalForWindow:self.window completionHandler:^(NSInteger result) {
if (result == NSOKButton) {
NSData * bookmark;
NSError * error;
bookmark = [panel.URL
bookmarkDataWithOptions:NSURLBookmarkCreationWithSecurityScope
includingResourceValuesForKeys:nil
relativeToURL:nil
error:&error
];
if (bookmark != nil) {
NSLog(@"success");
} else {
NSLog(@"error %@", error);
}
}
}];
Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"