Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 669
Prashant Avatar asked Mar 11 '23 18:03

Prashant


1 Answers

You can try something like this

-(void)downloadImage {
     if self.urlArray.count > 0) {
         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
                     }
                 }];
     }
     else {
         NSLog(@"All Images are downloaded do what u want")
     }
} 

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.

like image 153
Nirav D Avatar answered Mar 19 '23 09:03

Nirav D