Created
July 17, 2019 01:11
-
-
Save xjbeta/6ccdc3db5e15466da42be2b8b6a53733 to your computer and use it in GitHub Desktop.
App SandBox Security-Scoped
This file contains 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
// | |
// URLSecurityScope.swift | |
// Aria2D | |
// | |
// Created by xjbeta on 2017/1/24. | |
// Copyright © 2017年 xjbeta. All rights reserved. | |
// | |
import Foundation | |
// MARK: - Security-Scoped | |
class URLSecurityScope: NSObject { | |
static func resolvingBookmark(_ data: Data) -> URL? { | |
do { | |
var bool = false | |
let url = try URL(resolvingBookmarkData: data, | |
options: .withSecurityScope, | |
relativeTo: nil, | |
bookmarkDataIsStale: &bool) | |
// let _ = url.startAccessingSecurityScopedResource() | |
return url | |
} catch { | |
Log("resolveBookmarkError\(error)") | |
return nil | |
} | |
} | |
static func bookmarkData(for url: URL) -> Data? { | |
do { | |
let data = try url.bookmarkData(options: .withSecurityScope, | |
includingResourceValuesForKeys: nil, | |
relativeTo: nil) | |
return data | |
} catch { | |
Log("creatBookmarkError:\(error)") | |
return nil | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment