我需要向服务器发送一个文件。我用UIViewControllerRepresentable选择这个文件,它提供了文件的url,每次我尝试上传时,我都得到相同的信息:- Domain=NSCocoaErrorDomain Code=257“文件”example1.xml“无法打开,因为你没有查看它的权限。”我想我需要在info.plist上添加权限,但我找不到正确的权限。如果我在沙箱中选择一个文件,它就可以工作。
发布于 2021-07-29 01:00:55
我在URL上使用.startAccessingSecurityScopedResource ()解决了这个问题。例如:
` `var path = URL (string:"pathFile")!
//在读取文件之前
path.startAccessingSecurityScopedResource ()
//在最后
path.stopAccessingSecurityScopedResource ()
//关闭。`
资源https://developer.apple.com/documentation/foundation/nsurl/1417051-startaccessingsecurityscopedreso
https://stackoverflow.com/questions/68454668
复制相似问题