Search code examples
macosnsurlfoundationappstore-sandboxsecurity-scoped-bookmarks

Will a URL always create security scoped bookmarks with exactly the same byte pattern?


I want to maintain a list of folders, in a sandboxed Mac app. To do that, I need to make a security-scoped bookmark, using url.bookmarkData().

Is it guaranteed that the Data returned by this method is always the same byte pattern, for a given file URL?

That is, can I take a new url.bookmarkData() and test if a [Data] list contains a security-scoped bookmark for the same URL, by just checking the Data instances? Or do I need to resolve each Data into a URL and compare those?


Solution

  • Nope.

    Make a sandboxed Mac app. Then:

    1. Use FileManager's url(for:in:appropriateFor:create:) to get the .downloadsFolder, and then run it through destinationOfSymbolicLink(atPath:) to get a URL with a path like "/Users/me/Downloads"

    2. Use NSOpenPanel to ask the user for a file, and choose your Downloads folder. You'll get a URL with a path like "/Users/me/Downloads"

    Call .bookmarkData() on the URLs in #1 and #2. The Datas you get aren't even the same length.