Skip to content

Instantly share code, notes, and snippets.

@xjbeta
Created July 17, 2019 01:11
Show Gist options
  • Save xjbeta/6ccdc3db5e15466da42be2b8b6a53733 to your computer and use it in GitHub Desktop.
Save xjbeta/6ccdc3db5e15466da42be2b8b6a53733 to your computer and use it in GitHub Desktop.
App SandBox Security-Scoped
//
// 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