【问题标题】:Create a file in ApplicationScripts directory in a sandboxed macOS app在沙盒 macOS 应用程序的 ApplicationScripts 目录中创建文件
【发布时间】: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


【解决方案1】:

在关闭再打开 App Sandbox 功能后,它开始按预期工作。 ?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-06-11
    • 2012-06-22
    • 2019-10-11
    • 1970-01-01
    • 2018-11-21
    • 1970-01-01
    • 2021-07-06
    相关资源
    最近更新 更多