如果是单个的webview或者request请求,在请求的文件h中直接实现NSURLConnectionDelegate,并在m中添加下列实现下列两个方法:
- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {
return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];
}
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust])
//if ([trustedHosts containsObject:challenge.protectionSpace.host])
[challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]
forAuthenticationChallenge:challenge];
[challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
}
上述方法很不爽的是每个请求的地方都要加。
如果项目中用到了three20,直接修改“TTRequestLoader.m”即可,这个文件本身就已经实现了NSURLConnectionDelegate,
修改如下,只改这一个地方就行,处处可用。
///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)connection:(NSURLConnection *)connection
didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge{
//修改
if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust])
[challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];
[challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
TTDCONDITIONLOG(TTDFLAG_URLREQUEST, @" RECEIVED AUTH CHALLENGE LOADING %@ ", _urlPath);
[_queue loader:self didReceiveAuthenticationChallenge:challenge];
}
//添加
- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {
return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];
}
分享到:
相关推荐
IOS项目名更改工具 IOS项目名更改工具,一键修改,pod关联的项目也能直接更改。(更改前请备份原项目代码 ,以免丢失)
IOS签名证书 苹果签名w系统免费工具IOS签名证书 苹果签名w系统免费工具IOS签名证书 苹果签名w系统免费工具IOS签名证书 苹果签名w系统免费工具IOS签名证书 苹果签名w系统免费工具IOS签名证书 苹果签名w系统免费工具...
IOS11系统描述证书
ios证书指导ios证书指导ios证书指导ios证书指导ios证书指导ios证书指导ios证书指导ios证书指导ios证书指导ios证书指导ios证书指导ios证书指导ios证书指导ios证书指导ios证书指导ios证书指导ios证书指导ios证书指导...
iOS项目程序上线流程图文详解 .pdf
基于Xcode开发工具使用Swift语言开发的的IOS项目37大案例。Xcode 是运行在操作系统Mac OS X上的集成开发工具(IDE),Swift 是一种支持多编程范式和编译式的开源编程语言,苹果于2014年WWDC(苹果开发者大会)发布,...
iOS项目基本架构
ios10.3beta2证书下载,没有证书无法安装
IOS证书
iOS 真机测试证书
tomcat 发布ios下载安装 和证书部署 tomcat 发布ios下载安装 和证书部署
HBuilderX申请iOS证书在线打包iOS文档,介绍iOS证书的申请及打包过程!
iOS程序有固定的文件访问限制,只能在自己的沙盒内
Hera 项目脚手架,可以将小程序运行于iOS\Android\浏览器中 Hera 项目脚手架,可以将小程序运行于iOS\Android\浏览器中 Hera 项目脚手架,可以将小程序运行于iOS\Android\浏览器中 Hera 项目脚手架,可以将小程序...
iOS如何创建MDM证书
ios苹果签名工具含免费证书亲测可用(源代码下载).zip
最全的IOS项目框架,非常清晰,只需要按照这个模块写代码,非常好用。
IOS实战项目(项目架构)
flash ios发布 ipa 证书 大家都知道,Flash CS5 可以制作iPhone、iPad应用,并输出ipa格式文件。但是这是有前提的,你需要花99美刀/年成为Apple developer,这对于大多数只想尝尝新的朋友,代价有点太高了。 所以,...
5,提取本机shsh证书 ,从已经挂载的iOS设备上,转存储shsh2文件,用于平刷系统或者降级。6,一键安装巨魔商店,可以实现任意APP的自由安装。7,备份黑解ICCID证书。扩展功能:如果手机内存满而导致白苹果,删除一些...