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编译时加载
随机推荐
- <! - - ... - -> 注解
<A HREF TARGET> 指定超连结的分割视窗 <A HREF=#锚的名称> 指定锚名称的超连结 <A HREF> 指定超连结 <A NAME=锚的名称 ...
- js阻止表单提交
<!DOCTYPE html><html><head> <title>Simple Login Form</title> < ...
- 微信小程序 事件
事件详解 事件分类 事件分为冒泡事件和非冒泡事件: 冒泡事件:当一个组件上的事件被触发后,该事件会向父节点传递. 非冒泡事件:当一个组件上的事件被触发后,该事件不会向父节点传递. WXML的冒泡事件列 ...
- 第8步:安装Oracle
安装Oracle 注意,安装Oracle时需要以oracle用户身份执行,在那之前需要以root身份执行xhost+,即命令: 代码1 [root@sgdb1~]# xhost+ [root@sgdb ...
- Android多线程分析之中的一个:使用Thread异步下载图像
Android多线程分析之中的一个:使用Thread异步下载图像 罗朝辉 (http://blog.csdn.net/kesalin) CC 许可.转载请注明出处 打算整理一下对 Android Fr ...
- 第一次使用Xamarin就上手 - 安裝Xamarin
http://xamarintech.blogspot.tw/2013/06/xamarin-xamarin-step-by-step-part1.html http://xamarintech.bl ...
- 在本地模拟搭建zookeeper集群环境实例
先给一堆学习文档,方便以后查看 官网文档地址大全: OverView(概述) http://zookeeper.apache.org/doc/r3.4.6/zookeeperOver.html Get ...
- bootstrap3.3.6 CDN
<!-- Latest compiled and minified CSS --> <link rel="stylesheet" href="//max ...
- scrapy工程创建及pycharm运行
1.通过命令行创建scrapy工程项目 scrapy startproject (工程名) scrapy startproject myxml 2.利用爬虫模板设置爬虫文件 在这个过程中我们可以先利用 ...
- Oracle Schema Objects——Tables——Overview of Tables
Oracle Schema Objects Overview of Tables A table is the basic unit of data organization in an Oracle ...