【发布时间】:2018-06-26 09:44:49
【问题描述】:
我想在 macOS 应用程序的应用程序脚本目录中创建一个 (".scpt") 文件。
当我第一次启动应用程序时,我会提供一个NSOpenPanel 以获取存储到磁盘的应用程序脚本目录的安全范围书签。
let data = try url.bookmarkData(options: .withSecurityScope, includingResourceValuesForKeys: nil, relativeTo: nil)
... // store to disk
检索...
var bookmark: Bookmark = ... // load from storage
var isStale = false
let url = try! URL.init(resolvingBookmarkData: bookmark.value, options: .withSecurityScope, relativeTo: nil, bookmarkDataIsStale: &isStale
...并且书签的使用似乎有效:url.startAccessingSecurityScopedResource()returns true
但在该目录内创建文件失败:
let bundleUrl = Bundle.main.url(forResource: "foo", withExtension: "scpt")!
try! FileManager.default.copyItem(at: bundleUrl, to: url.appendingPathComponent("copyOfFoo.scpt"))
例外:
Operation not permitted
无法创建 copyOfFoo.scpt ... 无法复制,因为您无权访问“com...”
有什么提示吗?先感谢您。
【问题讨论】:
-
你在 Targets > Capabilities > App Sandbox > File Access 下有什么?
-
我将
User selected file设置为read/write
标签: swift macos security sandbox bookmarks