AFNetworking - Download multiple files + monitoring via UIProgressView

折月煮酒 提交于 2019-12-02 16:25:49

I think you will have to create your own UIProgressView, which I will call progressView for the example.

progressVu = [[UIProgressView alloc] initWithFrame:CGRectMake(x, y, width, height)];
[progressVu setProgressViewStyle: UIProgressViewStyleDefault];

Then just update the progress bar:

[operation setDownloadProgressBlock:^(NSInteger bytesWritten, NSInteger totalBytesWritten, NSInteger totalBytesExpectedToWrite) {

    float percentDone = ((float)((int)totalBytesWritten) / (float)((int)totalBytesExpectedToWrite));

    progressView.progress = percentDone;

    NSLog(@"Sent %d of %d bytes, %@", totalBytesWritten, totalBytesExpectedToWrite, path);
}];
[operation setDownloadProgressBlock:^(NSInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead) {

    float percentDone = ((float)((int)totalBytesRead) / (float)((int)totalBytesExpectedToRead));

    progressView.progress = percentDone;

}];

Imagine downloading 200+ files this way by assuming a file size of 1 MB each. What happens when you create such a bunch of requests (with a default timeout of 30s)? Right after 30 seconds you will be bombed by timeout errors.

Just sayin' Martin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!