Search code examples
iphonesdwebimage

How to know image has been downloaded in SDWebImage


Currently I am integrating SDWebImage in my project,

1)#import "UIButton+WebCache.h"

2)[button setImageWithURL:url placeholderImage:[UIImage imageNamed:@"no_photo.png"]];

Now I want to know when the image is downloaded successfully or not, How can I know this?


Solution

  • You can do this using the setImageWithURL: method and blocks like so:

    Start your downloading animation. Then use this to download the image into an image view (or button, as you seem to be doing that above).

        [imageView setImageWithURL:[NSURL URLWithString:imageURL]
                   placeholderImage:[UIImage imageNamed:@"YourPlaceholder.png"]
                            success:^(UIImage *image) {
                                // remove animation
    
                            }
                            failure:^(NSError *error) {
                                NSLog(@"thumbnail error: %@",error);
                                // handle failed download
    
                            }];