You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you want to provide your sandboxed app with persistent access to file system resources, you must enable security-scoped bookmark and URL access. Security-scoped bookmarks are available starting in macOS v10.7.3.
To add the bookmarks.app-scope or bookmarks.document-scope entitlement, edit the target’s .entitlements property list file using the Xcode property list editor. Use the entitlement keys shown in Table 4-4, depending on which type of access you want. Use a value of for each entitlement you want to enable. You can enable either or both entitlements.
func saveBookmark(item:ShortcutItem){
guard let url = item.fileUrl else{return}do{letbookmarkData=try url.bookmarkData(
options:.withSecurityScope,
includingResourceValuesForKeys:nil,
relativeTo:nil)
item.bookmark = bookmarkData
}catch{print("Failed to save bookmark data for \(url)", error)}}func loadBookmark(item:ShortcutItem)->URL?{
guard let data = item.bookmark else{returnnil}do{varisStale= false
leturl=tryURL(
resolvingBookmarkData: data,
options:.withSecurityScope,
relativeTo:nil,
bookmarkDataIsStale:&isStale
)
if isStale {saveBookmark(item: item)}return url
}catch{print("Error resolving bookmark:", error)returnnil}}
_ = url.startAccessingSecurityScopedResource()NSWorkspace.shared.open(url)
url.stopAccessingSecurityScopedResource()
Add entitlements
Enabling Security-Scoped Bookmark and URL Access
Read more
The text was updated successfully, but these errors were encountered: