Andrey Solovyov
Andrey Solovyov

Reputation: 1061

Handle non-picture URL with SDWebImage

I am using setImageWithURL:placeholderImage:options:andResize:withContentMode:success: method of SDWebImage. When I provide it with correct URL, pointing to picture, it works well. But when I feed it some non-picture URL (e.g. http://www.yandex.ru), SDWebImage does nothing, even success and failure blocks are not called.

How should I detect if SDWebImage would not get image from the URL specified?

Upvotes: 1

Views: 1680

Answers (2)

Vitalii Gozhenko
Vitalii Gozhenko

Reputation: 9354

Try to update SDWebImage to newest version and use new function instead of old: sd_setImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock

Upvotes: 1

Sandy Chapman
Sandy Chapman

Reputation: 11341

I'd recommend using the SDWebImageManager instead:

SDWebImageManager *manager = [SDWebImageManager sharedManager];
[manager downloadWithURL:imageURL
                 options:0
                 progress:^(NSInteger receivedSize, NSInteger expectedSize)
                 {
                     // progression tracking code
                 }
                 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished)
                 {
                     if (image)
                     {
                         // do something with image
                     }
                 }];

And then check the error value in the completed block.

Upvotes: 1

Related Questions