Type Method

URLByResolvingBookmarkData:options:relativeToURL:bookmarkDataIsStale:error:

Returns a new URL made by resolving bookmark data.

Declaration

+ (instancetype)URLByResolvingBookmarkData:(NSData *)bookmarkData options:(NSURLBookmarkResolutionOptions)options relativeToURL:(NSURL *)relativeURL bookmarkDataIsStale:(BOOL *)isStale error:(NSError * _Nullable *)error;

Parameters

bookmarkData

The bookmark data the URL is derived from.

options

Options 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 OR operators with any other options in this parameter) the NSURLBookmarkResolutionWithSecurityScope option.

relativeURL

The 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.

isStale

On 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.

error

The error that occurred in the case that the URL cannot be created.

Return Value

A new URL made by resolving bookmarkData.

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 resourceValuesForKeys:fromBookmarkData: method to obtain information about the bookmark, such as the last known path (NSURLPathKey) to help the user decide how to proceed.

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.

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, the CFURLStartAccessingSecurityScopedResource 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.

See Also

Creating an NSURL Object

initWithScheme:host:path:

Initializes a newly created NSURL with a specified scheme, host, and path.

Deprecated
URLWithString:

Creates and returns an NSURL object initialized with a provided URL string.

initWithString:

Initializes an NSURL object with a provided URL string.

URLWithString:relativeToURL:

Creates and returns an NSURL object initialized with a base URL and a relative string.

initWithString:relativeToURL:

Initializes an NSURL object with a base URL and a relative string.

fileURLWithPath:isDirectory:

Initializes and returns a newly created NSURL object as a file URL with a specified path.

initFileURLWithPath:isDirectory:

Initializes a newly created NSURL referencing the local file or directory at path.

fileURLWithPath:

Initializes and returns a newly created NSURL object as a file URL with a specified path.

initFileURLWithPath:

Initializes a newly created NSURL referencing the local file or directory at path.

fileURLWithPathComponents:

Initializes and returns a newly created NSURL object as a file URL with specified path components.

URLByResolvingAliasFileAtURL:options:error:

Returns a new URL made by resolving the alias file at url.

initByResolvingBookmarkData:options:relativeToURL:bookmarkDataIsStale:error:

Initializes a newly created NSURL that points to a location specified by resolving bookmark data.

fileURLWithFileSystemRepresentation:isDirectory:relativeToURL:

Returns a new URL object initialized with a C string representing a local file system path.

getFileSystemRepresentation:maxLength:

Fills the provided buffer with a C string representing a local file system path.

initFileURLWithFileSystemRepresentation:isDirectory:relativeToURL:

Initializes a URL object with a C string representing a local file system path.