In my app, I would like to access local file directory with security-scoped bookmark.
As mentioned in App Sandbox Design Guide, I store my user's specified folder (NSOpenPanel) in security-scoped bookmark (as NSData).
However, I find URLByResolvingBookmarkData is no longer available in Swift. I have no idea how can I access the url and grant the permission to the directory I previously chosen after relaunching my app. Any ideas?
/// OpenPanel and set the folderPath
var folderPath: NSURL? {
didSet {
do {
let bookmark = try folderPath?.bookmarkDataWithOptions(.SecurityScopeAllowOnlyReadAccess, includingResourceValuesForKeys: nil, relativeToURL: nil)
} catch {
print("Set bookMark fails")
}
}
}
init(byResolvingBookmarkData:options:relativeToURL:bookmarkDataIsStale:)
– Martin R