Viewing progress in alamo mode will not be updated when loading a file in swift 3

I want to upload an alamo fire file and use alert with progress to show it, but progress will not move when the progress of alamo progress.fractionCompleted increases. I use static var to equal progres.fractionCompleted, but it does not work either. here are my codes

let destination = DownloadRequest.suggestedDownloadDestination() Alamofire.download("example.com", to: destination).downloadProgress(queue: DispatchQueue.global(qos: .utility)) { (progress) in print("Progress: \(progress.fractionCompleted)") sixthLevelViewController.progressdownload = Float(progress.fractionCompleted) DispatchQueue.main.async { let alertController = UIAlertController(title: "Downloading", message: "please wait", preferredStyle: .alert) let progressDownload : UIProgressView = UIProgressView(progressViewStyle: .default) progressDownload.setProgress(ViewController.progressdownload, animated: true) progressDownload.frame = CGRect(x: 10, y: 70, width: 250, height: 0) alertController.view.addSubview(progressDownload) self.present(alertController, animated: true, completion: nil) } } .validate().responseData { ( response ) in print(response.destinationURL!.lastPathComponent) } 

** Remember that this will work well, and the problem is just updating the presentation of progress **

0
source share
1 answer

I think your code is incorrect: according to the last Alamofire docs I will give an example to show how you can change 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
source

Source: https://habr.com/ru/post/983893/


All Articles