【发布时间】:2019-05-01 11:23:55
【问题描述】:
我正在尝试使用文档选择器从 iCloud 导入一个文件夹,以使用 Alamofire 将其上传到服务器。我可以从 iCloud 导入单个文件,例如 .txt .pdf 文件,但我无法选择其中包含一些文件的文件夹。尝试选择文件夹后出现以下错误:
无法加载数据:Error Domain=NSCocoaErrorDomain Code=257 "The 文件 “xxxx”无法打开,因为您没有权限 查看它。” ... {Error Domain=NSPOSIXErrorDomain Code=13 "Permission denied"}}
这是我的代码:
someFunctionToGetPickedFilePath = { (filePath) in
let urlString = filePath.path
let fileWithPath: URL = URL.init(fileURLWithPath: urlString)
do {
let fileData = try Data(contentsOf: fileWithPath)
// upload the fileData to server with Alamofire upload request
} catch {
print("Unable to load data: \(error)")
}
}
"filePath" 这里的 URL 来自文档选择器功能,如下所示:
func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) {
// some code
}
我试图找到解决方案将近 2 天,但我似乎找不到解决方案。如何从 iCloud 中选择一个文件夹,为什么我会收到此权限被拒绝错误?任何回应都将受到高度赞赏。
【问题讨论】:
-
如何在 didPickDocumentAt 中获取文件夹?根据文档,这是不可能的,从逻辑上讲,我也看不到它,当您点击文件夹时,它必须打开内容,以便可以以任何方式选择它......?
-
我想我可以在允许文档选择器多选后选择一个文件夹。
标签: ios swift file-management uidocumentpickervc