Download Images One By One with url using SDWebimage

蓝咒 提交于 2019-12-06 08:43:10

问题


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.


回答1:


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.




回答2:


This is how you download image as independent image with SDWebImage in Swift

import SDWebImage

let downloader = SDWebImageManager()

downloader.imageDownloader?.downloadImage(with: URL(string: imageUrl), options: .highPriority, progress: { 
        (receivedSize, expectedSize, url) in
        // image is being downloading and you can monitor progress here
            }, completed: { (downloadedImage, data, error, success) in
                print(downloadedImage, data, success)
                //image is downloaded and ready to use
            })


来源:https://stackoverflow.com/questions/38267286/download-images-one-by-one-with-url-using-sdwebimage

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