Prashant Prashant - 5 months ago 44
Objective-C Question

Download Images One By One with url using SDWebimage

I need to Download images from

Array
of Url's, one by one and Display all at a Time.
Ex. I have an array of 10 URL's and I need to Download image One By One only, and display at a time.
I am Using
SDWebImage
for Download Images.
Please Help me.

Thanks.

Answer

You can try something like this

-(void)downloadImage {
     NSURL *url = [NSURL URLWithString:[self.urlArray firstObject]];
     SDWebImageManager *manager = [SDWebImageManager sharedManager];
     [manager downloadImageWithURL:imageURL
                  options:0
                 progress:^(NSInteger receivedSize, NSInteger expectedSize) {
                     // progression tracking code
                 }
                 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
                     if (image) {
                         [self.imageArray addObject:image];
                         [self.urlArray removeObjectAtIndex:0];
                         [self downloadImage];
                     }
                     else {
                         [self downloadImage]; //try download once again
                     }
                 }];
} 

Note:- Here urlArray is array of string url and imageArray array contain all the image that you have download.

call this method after you have got all the string url in urlArray.

Hope this will help you.