Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

351
Visualizações
Retrieve Alamofire estimatedTimeRemaining & file downloaded size

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.

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

Simple DownloadProgress class implementation based on having a Progress from Alamofire or other and a moving average taken from here How to estimate download time remaining (accurately)?

https://gist.github.com/akovalov/7b22735e1fb7f1117bf04659e214d785

over 4 years ago · Santiago Trujillo Relatório

0

I you check the Progress class you can find

open var totalUnitCount: Int64
open var completedUnitCount: Int64

you can use those variables

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda