下载并保存文件
let destination: DownloadRequest.DownloadFileDestination = { _, _ in
// var fileURL = self.createFolder(folderName: downloadFolderName)
var fileURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
let fileName = URL(string : currentFile.link )
fileURL = fileURL.appendingPathComponent((fileName?.lastPathComponent)!)
return (fileURL, [.removePreviousFile, .createIntermediateDirectories])
}
Alamofire.download(currentDownloadedFile.link , to: destination).response(completionHandler: { (DefaultDownloadResponse) in
print("res ",DefaultDownloadResponse.destinationURL!);
completion(true)
})
但是当我不想检查这个目录中的文件时,我得到了 nil
let filemanager:FileManager = FileManager()
let fileURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
let files = filemanager.enumerator(atPath: fileURL.absoluteString) // = nil
while let file = files?.nextObject() {
print(file)
}
如果我将本地路径保存到文件并且在重新加载应用程序后不会共享它 -> “共享”应用程序无法发送文件(mb 无法找到它)
你能帮帮我吗?怎么运行的 ?为什么当我打印所有文件时他没有找到?如何保存重新启动应用程序后将保存在同一链接中的文件
最佳答案
你使用了错误的 API
对于文件系统 URL,始终使用 path
,absoluteString
返回包含方案的完整字符串(例如 file://
或 http://
)
let files = filemanager.enumerator(atPath: fileURL.path)
关于下载 Alamofire 后快速保存文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55384987/