SVProgressHUD: SVProgressHUD.showProgress can't keep up with the updates
I’m using Alamofire to download a file and show the progress using SVProgressHUD.showProgress
Alamofire.download(.GET, "https://httpbin.org/stream/100", destination: destination)
.progress { bytesRead, totalBytesRead, totalBytesExpectedToRead in
dispatch_async(dispatch_get_main_queue()) {
let percentage = Float(totalBytesRead) / Float(totalBytesExpectedToRead)
print("downloading: \(percentage)")
SVProgressHUD.showProgress(percentage, status: "Downloading")
}
}
.response { _, _, _, error in
if let error = error {
print("Failed with error: \(error)")
} else {
print("Downloaded file successfully")
SVProgressHUD.dismiss()
//open file
}
}
It prints this really fast:
downloading: 0.000509328
downloading: 0.00115448
.....
downloading: 0.999199
downloading: 1.0
Downloaded file successfully
But SVProgressHUD can’t keep up with the updates and shows the progress really slow. It gets dismissed about 10 seconds later after printing Downloaded file successfully. Removing dispatch_async(dispatch_get_main_queue()) didn’t help either
About this issue
- Original URL
- State: open
- Created 8 years ago
- Comments: 15 (2 by maintainers)
I too am seeing this issue. The root of the problem is that showProgress is performing the update by adding it to the main NSOperationQueue. So if that queue doesn’t get time to process then no update. If I comment out that code and simply do the block immediately then it all works (though you may also still need to give time to the main runloop to process the screen update. I did this by calling RunLoop.main.run(until: Date().addingTimeInterval(0.01)) in my progress loop (this did not solve the original problem of the operation not getting time.))
So unless there is something else I don’t see, I don’t see any need to add this to an NSOperationQueue.
Note this also may be the cause of other reported issues so you might want to remove all the usages of NSOperationQueue and/or try GCD instead.
@osrl Actually, it’s the opposite! On simulator it works fine but stuttering occurs on real devices. (using Alamofire). Issue still there.
Update: more specifically, this occurs when the default mask is (.Gradient). Tested with (.Black) mask and was fine. @honkmaster there are many other (closed) issues with the same problem as this one. Any chance for a workaround or a response?