DownloadButton
DownloadButton copied to clipboard
Problem setting progress
Hi,
I m trying to set the progress to the stopDownloadButton
in a NSURLSessionDownloadTask
. I see the stopDownloadButton, but the progress is not increasing. Here is my block:
progress:^(NSProgress * _Nonnull downloadProgress) {
self.downloadButton.stopDownloadButton.progress = downloadProgress.fractionCompleted;
}
What am I doing wrong?
Thanks in advance,
Hi, perhaps that callback is not on the main thread? To properly update the UI it must be done on the main thread.
progress:^(NSProgress * _Nonnull downloadProgress) {[weak self] in
dispatch_async(dispatch_get_main_queue()) {
self?.downloadButton.stopDownloadButton.progress = downloadProgress.fractionCompleted
}
}
(Also good to weak reference self inside a block, to avoid retain cycles)