2

I'm trying to create a security scoped URL for a user provide file which happens to be an alias using this methods which uses a resolvedFinderAlias() method:

func storeBookmark(url: URL) -> Bool
{
    //  Resolve alias before storing bookmark
    let origURL = (url as NSURL).resolvedFinderAlias()

    //  Peek to see if we've seen this key before
    if let data = bookmarks[url] {
        if self.fetchBookmark(key: url, value: data) {
            Swift.print ("= \(url.absoluteString)")
            return true
        }
    }
    do
    {
        let options:URL.BookmarkCreationOptions = [.withSecurityScope,.securityScopeAllowOnlyReadAccess]
        let data = try url.bookmarkData(options: options, includingResourceValuesForKeys: nil, relativeTo: origURL)
        bookmarks[url] = data
        return self.fetchBookmark(key: url, value: data)
    }
    catch let error
    {
        NSApp.presentError(error)
        Swift.print ("Error storing bookmark: \(url)")
        return false
    }
}

which throws an error in attempt to use the resolved URL to as the relative URL; I had originally just swapped the passed in URL to the origURL which ddin't work either.

The only solution is to not do this, or to previously be passed in the original URL. It's almost as if you cannot swap URLs you must be supplied that from either an open dialog or a pasteboard drop.

Are URLs which are aliases not suitable for sandbox work ?

slashlos
  • 913
  • 9
  • 17

0 Answers0