你是否遇到了这种情况,好不容易把自签名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. 学习-go语言坑之for range

    引用自 http://studygolang.com/articles/9701 go只提供了一种循环方式,即for循环,在使用时可以像c那样使用,也可以通过for range方式遍历容器类型如数组. ...

  2. [LintCode] 合并排序数组

    A subroutine of merge sort. class Solution { public: /** * @param A and B: sorted integer array A an ...

  3. jQuery-实现图片的放大镜显示效果

    jQuery-实现图片的放大镜显示效果 by zhangxinxu from http://www.zhangxinxu.com 本文地址:http://www.zhangxinxu.com/word ...

  4. Java 运行环境介绍

    Java 语言特点: 跨平台性: 一次编译,到处运行.即不受操作系统限制,编译一次,可以在多个平台运行.而这个优势得益于 JVM(Java Virtual Machine, 即Java 虚拟机). 两 ...

  5. 名义人均GDP的背后,中国真实的人均GDP是1.2万美元!(中国GDP含金量较高)

    来源:天涯社区 根据IMF(国际货币基金组织)在今年4月的报告,2014年份中国人均GDP为7600美元,在185个国家当中排行第78位. 然而,根据楼主在国外行走多年的经验,巴西.墨西哥.马来西亚. ...

  6. MySQL小记

    一.MyISAM和InnoDB MyISAM引擎是不支持事务的,所以一般开发Mysql的引擎使用InnoDB. 事务处理上方面: MyISAM类型的表强调的是性能,其执行速度比InnoDB类型更快,但 ...

  7. Redis的LRU机制(转)

    原文:Redis的LRU机制 在Redis中,如果设置的maxmemory,那就要配置key的回收机制参数maxmemory-policy,默认volatile-lru,参阅Redis作者的原博客:a ...

  8. sql server升级打补丁

    原本:https://blog.csdn.net/kk185800961/article/details/72436415 sql server升级 sql server打补丁 sql server升 ...

  9. tomcat访问管理页面出现:403 Access Denied 解决方法

    点击红色框框出现以下403错误 打开context.xml文件 vim /usr/local/tomcat/webapps/manager/META-INF/context.xml <Conte ...

  10. 通信—HTTP与HTTPS

    HTTP是客户端浏览器或其他程序与Web服务器之间的应用层通信协议.在Internet上的Web服务器上存放的都是超文本信息,客户机需要通过HTTP协议传输所要访问的超文本信息. HTTPS(全称:H ...