In my cocoa app I use the following code to create a security-scoped bookmark from an NSURL that I got from an NSOpenPanel:
NSData *bookmarkData=[myURL bookmarkDataWithOptions:([NSURL instancesRespondToSelector:@selector(startAccessingSecurityScopedResource)] ? NSURLBookmarkCreationWithSecurityScope : 0) includingResourceValuesForKeys:(&NSURLPathKey==NULL ? [NSArray arrayWithObjects:NSURLVolumeIsLocalKey,nil] : [NSArray arrayWithObjects:NSURLPathKey,NSURLVolumeIsLocalKey,nil]) relativeToURL:nil error:&error];
and to resolve it, I use:
BOOL isStale;
myURL=[NSURL URLByResolvingBookmarkData:bookmarkData options:options relativeToURL:nil bookmarkDataIsStale:&isStale error:nil];
In Mac OS X Mavericks (10.9), this works fine when I create a bookmark for an external drive, like a USB stick. But in Yosemite (10.10), if the external drive is not mounted, the bookmark resolution doesn't return nil
as it does in Mavericks. Instead, it returns a url that points to Macintosh HD (i.e. [myURL path]
returns the string @"/"
). I noticed that in this case isStale==YES
.
Does somebody else experienced the same problem? Is this a known bug in Yosemite or am I missing some additional step to handle such a case? Is there a workaround?
This bug seems to be resolved in Mac OS X El Capitan.