【发布时间】:2016-05-19 15:32:11
【问题描述】:
如何在使用 Alamofire 重新下载之前检查给定文件是否已经下载?我正在使用suggestedDownloadDestination,所以Alamofire 会自动选择文件名并将其保存在选择的目录中,例如.CachesDirectory。问题是suggestedDownloadDestination 给出的值是DownloadFileDestination 类型,只有通过使用请求的response 调用他才会返回NSURL,但这样我就永远无法知道文件路径而不执行之前的请求。
这是我目前使用 Alamofire 下载文件的代码:
Alamofire.download(.GET, downloadLink, destination: destination).progress {
bytesRead, totalBytesRead, totalBytesExpectedToRead in
}.response {
request, response, data, error in
guard error == nil else {
return
}
// This will give me the file path but we're already in a Request!
print("\(destination(NSURL(string: "")!, response!))")
}
我错过了什么?
【问题讨论】:
-
你找到解决办法了吗?
-
@osrl 不幸的是,Alamofire 并没有让您有机会轻松地做到这一点,因为您会使用建议的DownloadDestination,我使用下载目录的自定义路径进行了修复并删除了建议的DownloadDestination
-
我尝试了
.head的方法找出目标文件路径,并在下载文件之前检查它是否存在。但是即使下载请求方法是.head,Alamofire 也会创建文件。所以这也没有用。