这是我用alamofire进行的下载功能,我已经注意到连接丢失,例如关闭wifi响应块不会产生任何恢复数据,该怎么办? 下载失败,恢复数据始终为
func StartDownload () {
let fileUrl = self.getSaveFileUrl(fileName: Data[0] as String)
let destination: DownloadRequest.DownloadFileDestination = { _, _ in
return (fileUrl, [.removePreviousFile, .createIntermediateDirectories])
}
downloadRequest = Alamofire.download(Data[0] as String , to:destination)
.downloadProgress { (progress) in
self.progressCircle.progress = progress.fractionCompleted
}
.validate()
.response { defaultDownloadResponse in
self.Timeer?.invalidate()
if (defaultDownloadResponse.error != nil) || defaultDownloadResponse.resumeData != nil {
self.startButton.isHidden = false
self.pauseButton.isHidden = true
print("someThing went wrong \(String(describing: defaultDownloadResponse.error))")
print(defaultDownloadResponse.resumeData as Any)
if let resumeDataa = defaultDownloadResponse.resumeData {
let Resume = CachableData(urll: self.Data[0].lastPathComponent as String, Resume: resumeDataa)
self.cacher.persist(item: Resume) { url, error in
if let error = error {
print("Text failed to persist: \(error)")
} else {
print("Text persisted in \(url?.absoluteString ?? "m")")
return
}
}
}
}
}
}
}