Returns a new URL made by resolving bookmark data.
SDKs
- iOS 4.0+
- macOS 10.6+
- Mac Catalyst 13.0+
- tvOS 9.0+
- watchOS 2.0+
Framework
- Foundation
Declaration
+ (instancetype)URLByResolvingBookmarkData:(NSData *)bookmarkData options:(NSURLBookmark Resolution Options)options relativeToURL:(NSURL *)relativeURL bookmarkDataIsStale:(BOOL *)isStale error:(NSError * _Nullable *)error;
Parameters
bookmarkDataThe bookmark data the URL is derived from.
optionsOptions taken into account when resolving the bookmark data.
To resolve a security-scoped bookmark to support App Sandbox, you must include (by way of bitwise
ORoperators with any other options in this parameter) theNSURLBookmarkoption.Resolution With Security Scope relativeURLThe base URL that the bookmark data is relative to.
If you are resolving a security-scoped bookmark to obtain a security-scoped URL, use this parameter as follows:
To resolve an app-scoped bookmark, use a value of
nil.To resolve a document-scoped bookmark, use the absolute path (despite this parameter’s name) to the document from which you retrieved the bookmark.
App Sandbox does not restrict which URL values may be passed to this parameter.
isStaleOn return, if
YES, the bookmark data is stale. Your app should create a new bookmark using the returned URL and use it in place of any stored copies of the existing bookmark.errorThe error that occurred in the case that the URL cannot be created.
Return Value
A new URL made by resolving bookmark.
Discussion
This method fails if the original file or directory could not be located or is on a volume that could not be mounted. If this method fails, you can use the resource method to obtain information about the bookmark, such as the last known path (NSURLPath) to help the user decide how to proceed.
To obtain a security-scoped URL from a security-scoped bookmark, call this method using the NSURLBookmark 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.
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 start method (or its Core Foundation equivalent, the CFURLStart function) 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.
Version note
Security-scoped bookmarks are not available in versions of macOS prior to OS X v10.7.3.