0

How can I show the progress of downloading using SVProgressHUD in Swift? I've implemented following code but it does not show the progress.

SVProgressHUD.show()
    Alamofire.download(
                url,
                method: .get,
                parameters: nil,
                encoding: JSONEncoding.default,
                headers: nil,
                to: destination).downloadProgress(closure: { (progress) in

                    DispatchQueue.main.async {
                        SVProgressHUD.showProgress(Float(progress.fractionCompleted))
                    }
                    print(progress.fractionCompleted)

                }).response(completionHandler: { (DefaultDownloadResponse) in

                    DispatchQueue.main.async {
                        SVProgressHUD.dismiss()
                    }
                })
Rohitax Rajguru
  • 893
  • 2
  • 13
  • 35
  • Alamofire's `download` should already run on the main thread so you dont need these `DispatchQueue.main.async` closures – Robert Dresler Feb 12 '19 at 12:50
  • Comment out the SVProgressHUD.dismiss() line. I think your network request responds so fast so your hud doesn't have time to show up. – asanli Feb 12 '19 at 13:04

2 Answers2

1

The question is 2 months old, but I will put this here as it may help someone. If anyone has a problem with SVProgressHUD not showing progress, check your progress increment. It should be between 0 and 1 (so the minimum possible progress is 0 and the maximum is 1), otherwise, the shown image will be a completed circle which makes the impression that the progress is not changing.

HemOdd
  • 697
  • 1
  • 7
  • 23
0

A workaround is to dismiss SVGProgress when progress reaches 100% 0r 1.0.

Also check https://github.com/SVProgressHUD/SVProgressHUD/issues/622? for more insight.