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
source share