SDWebImage 加载Https自签名证书时的图片问题
你是否遇到了这种情况,好不容易把自签名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自签名证书时的图片问题的更多相关文章
- 解决MWPhotoBrowser中的SDWebImage加载大图导致的内存警告问题
下面两种现象,用同一种方法解决 1.解决MWPhotoBrowser中的SDWebImage加载大图导致的内存警告问题 2.突然有一天首页访问图片很慢,至少隔20多秒所有图片才会出来.(解析:app使 ...
- SDWebImage 加载显示 GIF 与性能问题
SDWebImage 加载显示 GIF 与性能问题 SDWebImage 4.0 之前,可以用 UIImageView 显示 GIF 图.如果 SDWebImage 4.0 还这么做,只会显示静态图. ...
- SDWebImage 加载显示 WebP 与性能问题
SDWebImage 加载显示 WebP 与性能问题 本文包含自定义下载操作 SDWebImageDownloaderOperation 与编码器 SDWebImageCoder.SDWebImage ...
- 使用SDWebImage加载大量图片后造成内存泄露的解决办法
SDWebImage的知名度就不用说了,github上近10k的star,国内外太多的App使用其进行图片加载. 但是最近在使用过程中发现,在UITableView中不断加载更多的内容,使用SDWeb ...
- 关于android 加载https网页的问题
我在加载https网页时出现空白, 因此,我就百度一下,可以发现: webView.setWebViewClient(new WebViewClient(){ @Override public voi ...
- SDWebImage 加载网络图片失败,重新运行,就能加载成功。
现象: 使用SDWebImage 加载网络图片,偶尔会有一两张图片就是显示不出来.重新运行有时又可以了. 这个问题的原因是: 当SDWebImage 在加载图片的时候 我用的是- (void)sd_s ...
- 用SDWebImage加载FLAnimatedImage
用SDWebImage加载FLAnimatedImage 效果 源码 https://github.com/YouXianMing/Animations // // GifPictureControl ...
- 用tomcat配置https自签名证书,解决 ios7.1以上系统, 苹果inHouse发布
用tomcat配置https自签名证书,解决 ios7.1以上系统苹果inHouse发布不能下载安装的问题教程,话说,我其实最讨厌配置某某环境了,因为某一个小环节一旦出错,你的所有工作往往会功亏一篑, ...
- commonJs的运行时加载和es6的编译时加载
参考 : https://www.cnblogs.com/jerrypig/p/8145206.html 1.commonJs的运行时加载 2.ES6编译时加载
随机推荐
- Java语言中两种异常的差别
Java提供了两类主要的异常:runtime exception和checked exception.所有的checked exception是从java.lang.Exception类衍生出来的,而 ...
- 网页端的utf8和gb2312 之间关于osd 传参数的乱码问题
(0)HZK16 点阵字库原理及实现 (1)utf8 和 unicode gb2312之间的转换 (2)gb2312 的拓展 gbk 实现了更多的文字编码 像“瞭望塔”的瞭子在gb2312中是没有的 ...
- 【Raspberry Pi】GPIO-发光二极管控制
注意事项: 注意IO脚电流不能大于16mA,3V脚总电流不能大于50mA,所以两个二极管各上拉了400欧左右的电阻 采用物理针脚7和9做控制 其中output参数LOW为接通,HIGH为屏蔽 impo ...
- 【matlab】MTATLAB解线性方程组
在求解线性方程组时,会遇到以下几种情形:定解方程组.不定方程组.超定方程组.奇异方程组. 首先以定解线性方程组为例: format rat 化成分数 format short >> A= ...
- Android显示全局Dialog
1.需求:Dialog只能依附于某个具体的Activity显示,当我们需要一个全局的不依赖于某个Activity的Dialog时,应该怎么创建?类似于QQ消息提醒框 2.分析:我们可以在Service ...
- 《转》架设一个BLOG需要整合多少东西?
本文转载自大CC 1 Wordpress本身需要花费功夫的地方不多,比较容易,但Themes要花不少功夫调整,有时还得改CSS.推荐几个Wordpress Themes网站: - http://the ...
- 我的JavaScript笔记--面向对象
单例模式 ??(基于对象,不能批量生产) var person = { name: "ywb", sayHi: funct ...
- [LintCode] 二叉树的中序遍历
The recursive solution is trivial and I omit it here. Iterative Solution using Stack (O(n) time and ...
- Powershell Get File/Disk Size
知识点: 1.获取路径中的文件夹:Get-ChildItem $startFolder | Where-Object {$_.PSIsContainer -eq $True} | Sort-Obje ...
- 2 CDuiString的bug
重温了一下 Effective C++,发现这就是条款24所指出的问题,看来读书百遍不如写代码一遍啊 在Notify处理消息时会有很多if语句,我通常喜欢把常量放在双等号前面,变量放在后面,比如: ...