Search code examples
iostvossdwebimage

SDWebImage without ssl certificate


I try to set image via SDWebImage. But SDWebImage cancel operation. I've tried to get this image in Safari with url and Safari asked me about certificate. When I cancel dialog window I get this image.

Question is: Can I disable SDWebImage certificate validation without modifying this library?


Solution

  • I've spend a lot of time to drill into SDWebImage code and find solution. I wonder why docs doesn't say explicitly how to do that!

    Here is the sample code:

    NSURL *url = ... <image url here>
    UIImageView *imageView = ...
    [imageView sd_setImageWithURL:url placeholderImage:nil options:SDWebImageAllowInvalidSSLCertificates progress:^(NSInteger receivedSize, NSInteger expectedSize) {
            CGFloat percentage = ((CGFloat)receivedSize)/((CGFloat)expectedSize);
            //Track progress here if needed. 
        } completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
            ...
        }];
    

    The key moment is to pass SDWebImageAllowInvalidSSLCertificates option. Internally, this option will be transformed into proper option for shared image downloader.

    Hope that helps and hope i'll be able to find my answer next time i face the issue again!