gpt4 book ai didi

macos - 如何以编程方式删除启用沙箱的应用程序中应用程序文件夹内的文件

转载 作者:行者123 更新时间:2023-12-03 16:36:29 27 4
gpt4 key购买 nike

我正在尝试从我的 Cocoa 应用程序中删除应用程序文件夹内的文件。通过启用沙盒模式,我无法删除应用程序文件夹内的文件。

此沙盒模式有一些选项,用于启用对下载、图片、电影、音乐和用户选择的文件的读/写访问。

在此之前,我为用户选择的文件启用了读写访问权限,并使用 NSOpenPanel 完成了删除。它工作正常并删除应用程序文件夹内的文件,但每次我运行应用程序时它都会打开面板。在这里,我不需要任何用户交互/权限来删除应用程序文件夹内的文件。有没有解决方案可以删除具有上述定义约束的文件。

最佳答案

您需要使用Security-Scoped Bookmarks :

Your app’s access to file-system locations outside of its container—as granted to your app by way of user intent, such as through Powerbox—does not automatically persist across app launches or system restarts. When your app reopens, you have to start over. (The one exception to this is for files open at the time that your app terminates, which remain in your sandbox thanks to the OS X Resume feature).

关于macos - 如何以编程方式删除启用沙箱的应用程序中应用程序文件夹内的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21723319/

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