下载并保存文件
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无法找到文件)
您能帮我吗?怎么运行的 ?为什么当我打印所有文件时他没有找到它?如何保存文件,谁会在重启应用后将其保存在同一链接中
答案 0 :(得分:1)
您使用了错误的API
对于始终使用path
的文件系统URL,absoluteString
返回包含方案的完整字符串(例如file://
或http://
)
let files = filemanager.enumerator(atPath: fileURL.path)