i am trying to show progress view of the file that i am download when i printed the progress it is right but when i implement it on the progress view it is completely wrong it goes to 3000% here is my code. i am using MHRadialProgressView
downloadTask.observe(.progress) { (snapshot) -> Void in
// Download reported progress
let percentComplete = 100 * Double(snapshot.progress!.completedUnitCount) / Double(snapshot.progress!.totalUnitCount)
print("percentComplete")
self.progressView.moveNext(currentprogress as NSNumber!)
// Update the progress indicator
}
when i used MBProgressHUD here is the code for it
downloadTask.observe(.progress) { (snapshot) -> Void in
// Download reported progress
let percentComplete = 100 * Float(snapshot.progress!.completedUnitCount)
/ Float(snapshot.progress!.totalUnitCount)
let hud = MBProgressHUD.showAdded(to: (self.navigationController?.view)!, animated: true)
// Set the determinate mode to show task progress.
hud.mode = MBProgressHUDMode.determinate
hud.label.text = NSLocalizedString("Loading...", comment: "HUD loading title")
// Set up NSProgress
let progressObject = Progress(totalUnitCount: 100)
hud.progressObject = progressObject
// Configure a cancel button.
DispatchQueue.global(qos: .default).async(execute: {() -> Void in
// Do something useful in the background and update the HUD periodically.
while progressObject.fractionCompleted < 1.0 {
progressObject.becomeCurrent(withPendingUnitCount: 1)
progressObject.resignCurrent()
usleep(useconds_t(percentComplete))
}
DispatchQueue.main.async(execute: {() -> Void in
hud.hide(animated: true)
})
})
}
i am getting this error nanfatal error: Float value cannot be converted to UInt32 because it is either infinite or NaN
A few recommendations:
MBProgressHUD
, which allows you to set a progress object and forget about it.