你是否遇到了这种情况,好不容易把自签名HTTPS证书配置好了,访问https接口也成功了,但是图片加载不出来?

传了SDWebImageAllowInvalidSSLCertificates 还是没效果没效果(这种情况只适用于CA我觉得),

并且一直 HTTP load failed (error code: -999 [1:89]),

经过不懈努力,终于找到了在不修改SDWebimageDownloader.m源码的情况下的解决方案;

通过创建SDWebimageDownloader的分类来实现,如下:

.h 文件

1 #import "SDWebImageDownloader.h"

 @interface SDWebImageDownloader (AFNHttps)

 @end
 #import <SDWebImageDownloader.h>
#import "SDWebImageDownloader+AFNHttps.h" @implementation SDWebImageDownloader (AFNHttps) + (void)load {
     //设置SDWebImageDownloader的证书
[SDWebImageDownloader sharedDownloader].urlCredential = [self myUrlCredential];
} + (NSURLCredential *)myUrlCredential { NSString *thePath = [[NSBundle mainBundle] pathForResource:@"p12证书名" ofType:@"p12"];
//倒入证书 NSLog(@"thePath===========%@",thePath);
NSData *PKCS12Data = [[NSData alloc] initWithContentsOfFile:thePath];
CFDataRef inPKCS12Data = (__bridge CFDataRef)PKCS12Data; SecIdentityRef identity = NULL;
// extract the ideneity from the certificate
[self mosM_extractIdentity:inPKCS12Data toIdentity:&identity]; SecCertificateRef certificate = NULL;
SecIdentityCopyCertificate (identity, &certificate); return [NSURLCredential credentialWithIdentity:identity certificates:nil persistence:NSURLCredentialPersistencePermanent];;
} + (OSStatus)extractIdentity:(CFDataRef)inP12Data toIdentity:(SecIdentityRef*)identity {
OSStatus securityError = errSecSuccess;
CFStringRef password = CFSTR("p12证书密码");
const void *keys[] = { kSecImportExportPassphrase };
const void *values[] = { password };
CFDictionaryRef options = CFDictionaryCreate(NULL, keys, values, , NULL, NULL);
CFArrayRef items = CFArrayCreate(NULL, , , NULL);
securityError = SecPKCS12Import(inP12Data, options, &items);
if (securityError == )
{
CFDictionaryRef ident = CFArrayGetValueAtIndex(items,);
const void *tempIdentity = NULL;
tempIdentity = CFDictionaryGetValue(ident, kSecImportItemIdentity);
*identity = (SecIdentityRef)tempIdentity;
}
if (options) {
CFRelease(options);
}
return securityError;
}

SDWebImage 加载Https自签名证书时的图片问题的更多相关文章

  1. 解决MWPhotoBrowser中的SDWebImage加载大图导致的内存警告问题

    下面两种现象,用同一种方法解决 1.解决MWPhotoBrowser中的SDWebImage加载大图导致的内存警告问题 2.突然有一天首页访问图片很慢,至少隔20多秒所有图片才会出来.(解析:app使 ...

  2. SDWebImage 加载显示 GIF 与性能问题

    SDWebImage 加载显示 GIF 与性能问题 SDWebImage 4.0 之前,可以用 UIImageView 显示 GIF 图.如果 SDWebImage 4.0 还这么做,只会显示静态图. ...

  3. SDWebImage 加载显示 WebP 与性能问题

    SDWebImage 加载显示 WebP 与性能问题 本文包含自定义下载操作 SDWebImageDownloaderOperation 与编码器 SDWebImageCoder.SDWebImage ...

  4. 使用SDWebImage加载大量图片后造成内存泄露的解决办法

    SDWebImage的知名度就不用说了,github上近10k的star,国内外太多的App使用其进行图片加载. 但是最近在使用过程中发现,在UITableView中不断加载更多的内容,使用SDWeb ...

  5. 关于android 加载https网页的问题

    我在加载https网页时出现空白, 因此,我就百度一下,可以发现: webView.setWebViewClient(new WebViewClient(){ @Override public voi ...

  6. SDWebImage 加载网络图片失败,重新运行,就能加载成功。

    现象: 使用SDWebImage 加载网络图片,偶尔会有一两张图片就是显示不出来.重新运行有时又可以了. 这个问题的原因是: 当SDWebImage 在加载图片的时候 我用的是- (void)sd_s ...

  7. 用SDWebImage加载FLAnimatedImage

    用SDWebImage加载FLAnimatedImage 效果 源码 https://github.com/YouXianMing/Animations // // GifPictureControl ...

  8. 用tomcat配置https自签名证书,解决 ios7.1以上系统, 苹果inHouse发布

    用tomcat配置https自签名证书,解决 ios7.1以上系统苹果inHouse发布不能下载安装的问题教程,话说,我其实最讨厌配置某某环境了,因为某一个小环节一旦出错,你的所有工作往往会功亏一篑, ...

  9. commonJs的运行时加载和es6的编译时加载

    参考 : https://www.cnblogs.com/jerrypig/p/8145206.html 1.commonJs的运行时加载 2.ES6编译时加载

随机推荐

  1. C、C++数据类型所占字节数

    C标准中并没有详细给出规定那个基本类型应该是多少字节数.详细与机器.OS.编译器有关,比方相同是在32bits的操作系统系,VC++的编译器下int类型为占4个字节:而tuborC下则是2个字节. 所 ...

  2. org.springframework.beans.factory.parsing.BeanDefinitionParsingException

    今天在练习spring aop时.调试程序出现下面错误 org.springframework.beans.factory.parsing.BeanDefinitionParsingException ...

  3. 第5步:建立主机间的信任关系(sgdb1、sgdb2)

    5.1 Oracle用户下建立信任 5.11创建.ssh目录 [root@sgdb1 /]# su - oracle [oracle@sgdb1 ~]$ mkdir .ssh       创建一个.s ...

  4. Sublime Text 格式化代码快捷键

    首选项->按键绑定-用户 加入代码: {"keys": ["ctrl+alt+j"], "command": "reinde ...

  5. [Linux 学习] Centos 图形和命令行界面切换

    要想切换图形界面和命令行界面切换, 需修改一个文件... root 下, 到 /etc/inittab 修改 id:5:initdefault Linux系统有7个运行级别(runlevel): 运行 ...

  6. 主干(trunk)、分支(branch )、标记(tag) 用法示例 + 图解

    以svn为例,git的master相当于trunk,dev分支相当于branches --------------------------------------------------------- ...

  7. eclipse新建maven web工程

    每次建maven项目,总会有问题.决定在这整理一次,避免以后浪费时间. 最后目录为 1.首先修改pom.xml 之前老是出现明明改了 java compiler 已maven update 一下就又变 ...

  8. C#生成Windows服务

    1. 新建一个项目,或者从选择当前解决方案--右键-添加--新建项目 2. 选择Visual C#项目-->Windows 服务,填写要创建的服务名称(修改默认的WindowService1成为 ...

  9. 解决:JQuery "Uncaught ReferenceError: $ is not defined"错误

    重登了一下emo项目,发现新建朋友功能出了问题:MultiValueDictKeyError.查看了一下报错提示,发现ajax中发送的数据包中少了两个参数. 于是调试js前端,发现console报错: ...

  10. iframe下元素定位

    1.iframe基础知识: <frameset>生成的框架结构是依赖上级空间尺寸的,它的宽度或者高度必须有一个和上级框架相同.而<iframe>浮动框架可以完全由指定宽度和高度 ...