DownloadButton icon indicating copy to clipboard operation
DownloadButton copied to clipboard

Problem setting progress

Open josealonsogarcia opened this issue 8 years ago • 1 comments

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,

josealonsogarcia avatar Sep 12 '16 17:09 josealonsogarcia

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)

ryanholden8 avatar Sep 16 '16 14:09 ryanholden8