Estoy tratando de descargar un archivo usando Alamofire. Para mostrar el progreso, estoy usando downloadProgress de alamofire. Obtuve el porcentaje de progreso de él. Pero necesito mostrar el total de Mb/Kb descargados hasta el momento y también el tiempo restante estimado. Aquí está mi código:
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) } }Publicar el progreso mediante notificación
func postProgress(progress: Progress) { NotificationCenter.default.post(name: .DownloadProgress, object: progress) }Mostrando mi progreso usando los siguientes códigos
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) } }Estoy obteniendo progreso.fracción Completada perfectamente. Pero el progreso.estimatedTimeRemaining, el progreso.fileCompletedCount y el progreso.fileTotalCount siempre es nulo.
Implementación simple de la clase DownloadProgress basada en tener un Progress de Alamofire u otro y un promedio móvil tomado de aquí ¿Cómo estimar el tiempo de descarga restante (con precisión)?
https://gist.github.com/akovalov/7b22735e1fb7f1117bf04659e214d785