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

橙三吉。 提交于 2019-12-02 10:01:50

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...
                }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!