AFNetworking - check downloaded bytes before resuming file download?

I use AFDownloadRequestOperation to download files through the AFNetworking Framework and whenever I pause the file while downloading, then resume it later setProgressiveDownloadProgressBlock will start returning values ​​for totalBytesRead from scratch while the file is partially downloaded. Therefore, the block after displaying the remaining percentage of calls to setCompletionBlockWithSuccess files

But, I want to show the correct progress in the progress bar, so how do I get the correct percentage of the downloaded file?

+4
source share
1 answer

This is what I use

[operation setDownloadProgressBlock:^(NSUInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead) { NSLog(@"Operation%i: bytesRead : %d", i, bytesRead); NSLog(@"Operation%i: totalBytesRead : %lld", i, totalBytesRead); NSLog(@"Operation%i: totalBytesExpectedToRead: %lld", i, totalBytesExpectedToRead); if (totalBytesExpectedToRead > 0) { self.progressView.progress = (float)totalBytesRead / totalBytesExpectedToRead; } }]; 

A check was introduced due to the fact that totalBytesExpectedToRead can sometimes become -1, which violates the smoothness of progressview progress [it should also be noted that the problem from NSUrlconnection is that hrader returns -1 as the expected size to read]

(float)totalBytesRead / totalBytesExpectedToRead * 100 gives a percentage

-1
source

Source: https://habr.com/ru/post/1484828/


All Articles