没有 ssl 证书的 SDWebImage

Sev*_*lyk 5 ios sdwebimage tvos

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

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

Thu*_*ara 6

使用

UIImageView_name.sd_setImage(with: URL(string: logo), placeholderImage: nil, options: .allowInvalidSSLCertificates)
Run Code Online (Sandbox Code Playgroud)

代替

UIImageView_name.sd_setImage(with: URL(string: logo))
            UIImageView_name
Run Code Online (Sandbox Code Playgroud)

用于 UIButton 使用

UIButton_name.sd_setImage(with: URL(string: customer.getProfilePic()), for: .normal, placeholderImage: nil, options: .allowInvalidSSLCertificates, completed: nil)
Run Code Online (Sandbox Code Playgroud)


Vla*_*sov 4

我花了很多时间钻研 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) {
        ...
    }];
Run Code Online (Sandbox Code Playgroud)

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

希望这有帮助,并希望下次我再次遇到这个问题时能够找到答案!