'The resumeData always returns nil if the download request is cancelled
I am downloading data using Alamofire downloadRequest but in some scenarios I am cancelling downloadRequest and store data using resumeData in Alamofire version 4.5 but now I updated pod to latest Alamofire 5.4.4 version and now I am getting resumeData nil when I cancel downloadRequest.
Follow sharing code
static func downloadUserGuide(_ downloadLink: String, _ completion:@escaping(Bool) -> Void) {
if let data = UserDefaults.standard.data(forKey: downloadLink) {
resumeDownloadUserGuide(resumeData: data, userGuide.usermanual, { isDownloaded in
completion(isDownloaded)
})
}else{
self.request = AF.download(downloadLink, to: kDestination)
.downloadProgress { progress in
Console.log("Download Progress: \(progress.fractionCompleted)")
}
.responseData { response in
if response.value != nil {
if !self.userGuide.isInvalidated {
try! realm.write {
self.userGuide.pdfLinkURL = response.fileURL?.path ?? ""
}
}
saveUserGuideInDB(self.userGuide)
Console.log("Download successfull")
UserDefaults.standard.removeObject(forKey: downloadLink)
completion(true)
}else if response.error != nil {
if let resumeData = response.resumeData {
UserDefaults.standard.set(resumeData, forKey: downloadLink)
}
completion(false)
}
}
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
