在alamo fire中的进度视图在swift中下载文件时不会更新3

问题描述:

我想用alamo fire下载文件并使用带有进度的alert来显示它,但是当alamo fire progress.fractionCompleted增加时不会移动进度我使用static VAR等于progres.fractionCompleted,但它不工作太 这里是我的代码在alamo fire中的进度视图在swift中下载文件时不会更新3

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) 
     } 

**请记住,这将工作做好,问题只是更新发展观**

我想你代码是错误的:根据latest Alamofire文件,我举例说明如何修改代码:

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

迅速不让我跑,因为RetunzAPIProgress –

+0

我已经更新我的代码,让我知道你已经解决了应用.. –

+0

OK忘记了这一点,我用另一种代码但有另一个问题,请帮助我,并在此后固定我会回答这个问题,我自己在这里是该问题的链接 https://*.com/questions/46137799/why-alamo-fire-download -progress式警报,将闪烁和最落后屏-ST –