Contents

startAccessingSecurityScopedResource()

In an app that has adopted App Sandbox, makes the resource pointed to by a security-scoped URL available to the app.

Declaration

func startAccessingSecurityScopedResource() -> Bool

Return Value

true if the request to access the resource succeeded; otherwise, false.

Discussion

When you obtain a security-scoped URL, such as by resolving a security-scoped bookmark, you can’t immediately use the resource it points to. To make the resource available to your app, by way of adding its location to your app’s sandbox, call this method on the security-scoped URL. You can also use Core Foundation equivalent, the CFURLStartAccessingSecurityScopedResource(_:) function.

If this method returns true, then you must relinquish access as soon as you finish using the resource. Call the stopAccessingSecurityScopedResource() method to relinquish access. You must balance each call to startAccessingSecurityScopedResource() for a given security-scoped URL with a call to stopAccessingSecurityScopedResource(). When you make the last balanced call to stopAccessingSecurityScopedResource(), you immediately lose access to the resource in question.

See Also

Working with Bookmark Data