Created
October 25, 2024 18:11
-
-
Save delasign/c8a86aeffe03d836381bbd02c2d10848 to your computer and use it in GitHub Desktop.
Sample code for creating a bookmark with a security scope in Swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
func createSecurityScopedBookmark(for url: URL) -> Data? { | |
do { | |
// Create a bookmark from the selected URL | |
let bookmarkData = try url.bookmarkData(options: .securityScopeAllowOnlyReadAccess, includingResourceValuesForKeys: nil, relativeTo: nil) | |
debugPrint("\(DebuggingIdentifiers.actionOrEventSucceded) createSecurityScopedBookmark - \(bookmarkData)") | |
return bookmarkData | |
} catch { | |
debugPrint("\(DebuggingIdentifiers.actionOrEventFailed) createSecurityScopedBookmark error \(error)") | |
return nil | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment