I'm working with document based security scoped bookmark to store references to files in a document. I create them like so:
_bookmark = [_url bookmarkDataWithOptions: NSURLBookmarkCreationWithSecurityScope
includingResourceValuesForKeys: nil
relativeToURL: relativeURL
error: error];
The relativeURL
contains the URL to the document that will store the bookmark.
I later resolve the bookmark using:
resolvedURL = [NSURL URLByResolvingBookmarkData: bookmark
options: NSURLBookmarkResolutionWithoutMounting | NSURLBookmarkResolutionWithSecurityScope
relativeToURL: url
bookmarkDataIsStale: &isStale
error: error];
This works as long as the document and referred files stay on the initial machine. I can then move and rename them and they keep working.
On the other hand, if I zip up the folder containing the document and files, and extract them on another machine, the bookmarks don't resolve.
The presented error is code 4: File doesn't exist.
I verified that the document still contains its security scope attribute and it does. Of course both the document and referred file actually exist.
I tried creating the bookmark data from relative URLs, but that doesn't change anything. Requesting the URL from the bookmark always shows an absolute URL.
How can I make sure that the bookmarks resolve when the document and files are transferred to another machine?
Update
This problem has been confirmed by Apple. It's tracked under radar: 24126953
. Unfortunately, I was told they internally do not agree on whether this should get fixed or not. I hope they will someday.