首页 > 解决方案 > 没有 ssl 证书的 SDWebImage

问题描述

我尝试通过 SDWebImage 设置图像。但 SDWebImage 取消操作。我试图在 Safari 中使用 url 获取此图像,而 Safari 向我询问了证书。当我取消对话窗口时,我得到了这个图像。

问题是:我可以在不修改此库的情况下禁用 SDWebImage 证书验证吗?

标签: iostvossdwebimage

解决方案


我花了很多时间钻研 SDWebImage 代码并找到解决方案。我想知道为什么文档没有明确说明如何做到这一点!

这是示例代码:

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) {
        ...
    }];

关键时刻是通过SDWebImageAllowInvalidSSLCertificates期权。在内部,此选项将转换为共享图像下载器的正确选项。

希望这会有所帮助,并希望下次我再次面对这个问题时能够找到我的答案!


推荐阅读