3

How to show a progressbar during image downloading?

My code here:

 [picView setImageWithURLRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:picURL]] placeholderImage:[UIImage imageNamed:@"placeholder.png"] success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
    NSLog(@"success");


} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
    NSLog(@"fail");
}    
 ];

Thank you in advance.

webmastx
  • 683
  • 1
  • 8
  • 30
  • You will get answer for this question in below page. http://stackoverflow.com/questions/13821428/afnetworking-setimagewithurlrequest-download-progress/36984041#36984041 – Jegan May 02 '16 at 13:50

2 Answers2

7

A progress bar is probably not the correct UI for this. Instead, you should probably use an indeterminate progress indicator (spinning bars). To do this in AFNetworking, use setImageWithURLRequest:placeholderImage:success:failure:, hiding the progress indicator in success and failure.

If you did want to track the progress of a request, you would have to use AFImageRequestOperation, and do setDownloadProgressBlock:.

mattt
  • 19,544
  • 7
  • 73
  • 84
  • 7
    Mattt, can you elaborate on why showing a progress bar is not the correct way to show the progress of an image download? – Marin Todorov Oct 31 '12 at 08:34
0

Take a look at this cocoa pod: https://github.com/xmartlabs/XLRemoteImageView . It allow you to show a progress indicator and also be updated about UIImage download progress. It uses objective-c internals and AFNetworking UIImage category to achieve what you want. I hope it helps you.

mtnBarreto
  • 282
  • 1
  • 3
  • 9