tags:

views:

38

answers:

1

I am using the new NSURL bookmark data API introduced in OS X 10.6 to store an "alias" to a file system resource. When I use

+[NSURL URLByResolvingBookmarkData:options:relativeToURL:bookmarkDataIsStale:error:]

to resolve the bookmark data, I get nil if the file no longer exists. Since I am not passing NSURLBookmarkResolutionWithoutUI in the bookmark resolution options, I expected to get a dialog, like that shown by the Finder when you open an alias file that no longer resolves (i.e. a dialog to cancel, fix the alias, etc...).

Is there a way to have NSURL automatically prompt to reconnect/resolve the broken bookmark data?

The bookmark data is created via:

NSError *err
NSData *bookmarkData = [myFileURL bookmarkDataWithOptions:NSURLBookmarkCreationSuitableForBookmarkFile
                           includingResourceValuesForKeys:nil
                                            relativeToURL:nil
                                            error:&err];

though I get the same outcome if I use 0 for the options instead of NSURLBookmarkCreationSuitableForBookmarkFile.

I attempt to resolve the same bookmarkData via:

BOOL stale;
NSError *err
NSURL *resolvedURL = [NSURL URLByResolvingBookmarkData:self.bookmarkData
                                               options:0
                         relativeToURL:nil
                               bookmarkDataIsStale:&stale
                                                 error:&err];

Going through the dance of writing the bookmark data to a finder alias file and then resolving the URL by reading bookmark data from that file followed by the above method does not produce the desired UI result either (though opening the alias file in the Finder does produce the desired UI dialog).

+2  A: 

No. The UI potentially involved in bookmark/alias resolution is that displayed if the target is on an unmounted fileserver which requires authentication to connect. The reconnection dialog is provided by the Finder in response to an unresolvable alias; if you want your application to have similar behavior, you will need to implement it yourself.

Nicholas Riley
Thanks. I'll file a bugreport; the documentation is a little, ah, sparse on the topic.
Barry Wark