progress view in alamo fire will not update when downloading file in swift 3

前端 未结 1 1519
谎友^
谎友^ 2021-01-26 15:17

I want to download a file with alamo fire and using alert with progress to show it but the progress will not move when alamo fire progress.fractionCompleted increased I use stat

相关标签:
1条回答
  • 2021-01-26 15:45

    I think your code is wrong: according to the latest Alamofire documents I make an example to show how you can modify your code:

    let destination: DownloadRequest.DownloadFileDestination = { _, _ in
            let documentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory,
                                                                    .userDomainMask, true)[0]
            let documentsURL = URL(fileURLWithPath: documentsPath, isDirectory: true)
            let fileURL = documentsURL.appendingPathComponent("myfile.pdf")
    
            return (fileURL, [.removePreviousFile, .createIntermediateDirectories]) }
    
    func requestDownloadInfo(url:String) {
                Alamofire.download(url, to :destination)
                    .downloadProgress(queue: utilityQueue) { progress in
                        let progressDic = ["progress" : progress.completedUnitCount, "total" :  progress.totalUnitCount, "fraction" : progress.fractionCompleted] as [String:Any]
                        // here you can show your alert using fraction value..
                    }
                    .responseData { response in
                      // check your file after download or check errors...
                    }
    }
    
    0 讨论(0)
提交回复
热议问题