2017-09-06 55 views
0

我想用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) 
     } 

**請記住,這將工作做好,問題只是更新發展觀**

回答

0

我想你代碼是錯誤的:根據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://stackoverflow.com/questions/46137799/why-alamo-fire-download -progress式警報,將閃爍和最落後屏-ST –

相關問題