问题描述
我第一次在应用中使用 macOS 沙盒和文件路径书签。
阻碍我理解的一件事是,我的应用似乎能够打开任何文件夹路径,而不管沙箱如何。
例如,我可以访问启动守护程序路径的文件结构和文件内容(我认为这对沙盒应用来说是不受限制的)。
这是我从一个干净的 Swift UI/AppKit App Delegate 项目修改而来的我的应用委托,以展示这一点。
import Cocoa
import SwiftUI
@main
class AppDelegate: NSObject,NSApplicationDelegate {
var window: NSWindow!
func applicationDidFinishLaunching(_ aNotification: Notification) {
let url = URL(fileURLWithPath: "/Library/launchdaemons")
if let enumerator = FileManager.default.enumerator(at: url,includingPropertiesForKeys: [.isRegularFileKey,.isDirectoryKey],options: [.skipsHiddenFiles,.skipsPackageDescendants]) {
for case let fileURL as URL in enumerator {
print(fileURL);
do {
let contents = try String(contentsOf: fileURL,encoding: .utf8)
print(contents)
} catch {
}
}
}
}
func applicationWillTerminate(_ aNotification: Notification) {
// Insert code here to tear down your application
}
}
我已在应用的沙盒权限中将“用户选择的文件”设置为 none
。
我在这里错过了什么?为什么这个应用可以访问这个路径?
仅供参考 - 我只是在 Xcode 调试器中运行它。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)