我需要将文件发送到服务器。我使用提供文件 url 的 UIViewControllerRepresentable 选择此文件,每次尝试上传时都会收到相同的消息:- Domain=NSCocoaErrorDomain Code=257 “无法打开文件“example1.xml”,因为您没有无权查看。” . 我想我需要在 info.plist 上添加权限,但我找不到合适的权限。如果我在沙箱中选择一个文件,它就可以工作。
问问题
98 次
1 回答
0
我通过在 URL 上使用 .startAccessingSecurityScopedResource () 解决了这个问题。例如:
`var path = URL(字符串:“pathFile”)!
//读取文件之前
path.startAccessingSecurityScopedResource()
//在最后
path.stopAccessingSecurityScopedResource()
//关闭。`
资源https://developer.apple.com/documentation/foundation/nsurl/1417051-startaccessingsecurityscopedreso
于 2021-07-28T17:00:54.633 回答