gpt4 book ai didi

swift - 在沙盒 macOS 应用程序的 ApplicationScripts 目录中创建文件

转载 作者:行者123 更新时间:2023-11-30 11:23:24 31 4
gpt4 key购买 nike

我想在 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()返回true

但是在该目录内创建文件失败:

let bundleUrl = Bundle.main.url(forResource: "foo", withExtension: "scpt")!
try! FileManager.default.copyItem(at: bundleUrl, to: url.appendingPathComponent("copyOfFoo.scpt"))

异常(exception):

不允许操作

Failed to create copyOfFoo.scpt ... couldn’t be copied because you don’t have permission to access “com...

有什么提示吗?先感谢您。

最佳答案

再次关闭和打开应用程序沙箱功能后,它开始按预期工作。 😄

关于swift - 在沙盒 macOS 应用程序的 ApplicationScripts 目录中创建文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51039755/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com