I am trying to download a file using Alamofire. To show progress, i am using downloadProgress from alamofire. I got the progress percentage from it. But i need to show the total Mb/Kb downloaded so far and estimated time remaining as well. Here is my code:
AF.download("http://ipv4.download.thinkbroadband.com/200MB.zip",
method: .get,
parameters: nil,
encoding: URLEncoding.default,
headers: nil,
interceptor:nil,
to: destination)
.downloadProgress { progress in
self.postProgress(progress: progress)
}
.responseData { response in
if let data = response.result.value {
// let image = UIImage(data: data)
}
}
Posting the progress using notification
func postProgress(progress: Progress) {
NotificationCenter.default.post(name: .DownloadProgress, object: progress)
}
Showing my progress using the following codes
if let progress = notification.object as? Progress {
progressBar.setProgress(Float(progress.fractionCompleted), animated: true)
progressInNumberView.text = "\(Int64(progress.fractionCompleted*100))%"
remianingView.text = "\(progress.fileCompletedCount) / \(progress.fileTotalCount)"
if let estimatedTimeRemaining = progress.estimatedTimeRemaining {
remianingView.text = format(estimatedTimeRemaining)
}
}
I am getting progress.fractionCompleted perfectly. But progress.estimatedTimeRemaining, progress.fileCompletedCount and progress.fileTotalCount is always nil.