测试文件系统授权不适用于MacOS Catalina下的受保护文件夹

根据WWDC 701“ macOS Security中的高级功能”,Apple的建议是使用FileManager.default.isReadableFile,FileManager.default.isWritableFile来测试文件系统授权。但是这些API始终返回true,并且无论用户是否允许应用访问这些文件夹,我们都可以始终删除文件夹中的文件。

以下是代码和现象

let path = "/Users/xxx/Documents"
let file = "/Users/xxx/Documents/1.png"
let isReadable = FileManager.default.isReadableFile(atPath: file) //return true
let isWritable = FileManager.default.isWritableFile(atPath: file) //return true
try? FileManager.default.removeItem(atPath: file) // file will be deleted
guard let files = try? FileManager.default.contentsofDirectory(atPath: path) else {
            return
} //This will trigger user consent prompt for the first time

受保护的文件夹中的文件可以在授权之前删除。这是苹果的Bug吗?

inzhatzi 回答:测试文件系统授权不适用于MacOS Catalina下的受保护文件夹

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3140798.html

大家都在问