Created
October 25, 2024 18:22
-
-
Save delasign/01eceafb737f98f666c5a3b8dfb39d38 to your computer and use it in GitHub Desktop.
Sample function for converting data into a bookmark with security scope.
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 getBookmarkedURL(data: Data) -> URL? { | |
var isStale = false | |
do { | |
let url = try URL(resolvingBookmarkData: data, options: .withSecurityScope, relativeTo: nil, bookmarkDataIsStale: &isStale) | |
debugPrint("\(DebuggingIdentifiers.actionOrEventInProgress) getBookmarkedURL is Stale ? : \(isStale) | url: \(url).") | |
guard !isStale, url.startAccessingSecurityScopedResource() else { | |
debugPrint("\(DebuggingIdentifiers.actionOrEventFailed) getBookmarkedURL - bookmark has expired. Request access again to proceed.") | |
// TO DO: Mark Bookmark as stale | |
return nil | |
} | |
return url | |
} catch { | |
debugPrint(" \(DebuggingIdentifiers.actionOrEventFailed) getBookmarkedURL - error \(error.localizedDescription).") | |
return nil | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment