Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

352
Views
Recuperar el tiempo restante estimado de Alamofire y el tamaño descargado del archivo

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.

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

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

over 4 years ago · Santiago Trujillo Report

0

Si revisas la clase de Progreso que puedes encontrar

 open var totalUnitCount: Int64 open var completedUnitCount: Int64

puedes usar esas variables

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!