ndalias icon indicating copy to clipboard operation
ndalias copied to clipboard

Deprecation

Open nathanday opened this issue 13 years ago • 7 comments

Apple have added methods with 10.6 that does everything that NDAlias does,

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

+[NSURL bookmarkDataWithContentsOfURL:error:];
-[NSURL bookmarkDataWithOptions:includingResourceValuesForKeys:relativeToURL:error:];
+[NSURL writeBookmarkData:toURL:options:error:];

nathanday avatar Aug 21 '11 13:08 nathanday

Except work on 10.5 and older, as well as 10.6 and newer. :)

(Nathan, is the point of your note to discourage new uses of NDAlias, or do you want to add bookmark-related API to NDAlias, or...? I'm just confused, since 10.6 is hardly news...)

seanm avatar Aug 22 '11 14:08 seanm

Basicly I am saying if you are writing software for 10.6+ only you are better of using apples mechanism, I will still support bug fixes for NDAlias, if NDAlias does not work on 10.7 I will look at fixing that, though if there is too much work for that I might just change NDAlias to use apples api underneath for 10.7+, so that developers can use it for projects that need to support quite old versions of Mac OS X as well as 10.6+. I have no plan to remove NDAlias from GitHub, it will be around for quite a will still.

nathanday avatar Aug 22 '11 21:08 nathanday

I came across a slight 'problem' (the problem being sandboxed apps! :P) with Apple's implementation when trying to switch from NDAlias. As such I'll most likely be sticking to NDAlias, even for my 10.6+ apps.

There's an important message RE the initByResolvingBookmarkData methods in the docs:

To obtain a security-scoped URL from a security-scoped bookmark, call this method using the NSURLBookmarkResolutionWithSecurityScope option. In addition, to use security scope, you must first have enabled the appropriate entitlements for your app, as described in “Enabling Security-Scoped Bookmark and URL Access” in Entitlement Key Reference.

To then obtain access to the file-system resource pointed to by a security-scoped URL (in other words, to bring the resource into your app’s sandbox), call the startAccessingSecurityScopedResource method (or its Core Foundation equivalent) on the URL.

For an app-scoped bookmark, no sandboxed app other than the one that created the bookmark can obtain access to the file-system resource that the URL (obtained from the bookmark) points to.

For a document-scoped bookmark, any sandboxed app that has access to the bookmark data itself, and has access to the document that owns the bookmark, can obtain access to the resource.

Security-scoped bookmarks are not available in versions of OS X prior to OS X v10.7.3.

pjrobertson avatar Jun 10 '12 12:06 pjrobertson

I am surprised NDAlias would work to get around this in sandboxed app, or even work at all. If any issues come up with any version of Mac OS X I will look into fixing them.

nathanday avatar Jun 12 '12 04:06 nathanday

According to http://stackoverflow.com/questions/1619073/how-do-you-create-an-alias-in-cocoa-is-a-symlink-good-enough

"Bookmark data is not an alias. If you pass that data or a bookmark file to the Alias Manager, the Alias Manager will turn up its nose at it."

but seems to work just fine for me.

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

if(!bookmarkData || ![NSURL writeBookmarkData:bookmarkData toURL:dstURL options:NSURLBookmarkCreationSuitableForBookmarkFile error:&err]) {

    NSLog(@"Failed to create link %@ -> %@: %@", srcURL, dstURL, err);
}

tcurdt avatar Oct 31 '13 13:10 tcurdt

tcurdt, maybe there's a confusion between the multiple meanings of "alias". There's the AliasRecord data structure and related APIs, and there are 'alias' files that the Finder creates. I suspect the latter can work with Alias Manager or CF/NSURL APIs.

seanm avatar Oct 31 '13 14:10 seanm

FWIW there is a CFURL function to convert old-style alias records to bookmark data: CFURLCreateBookmarkDataFromAliasRecord. ~~It's not mentioned in the reference docs, though it is right there in the .h so it doesn't appear to be "undocumented" or anything.~~ In the reference docs.

jessepeterson avatar Jun 24 '15 07:06 jessepeterson