允许未经证实的SSL证书中的UIWebView
2013-11-28 23:33
239 查看
I'm embedding a website in a UIWebView.我的网站嵌入在一个UIWebView。 During development I have it pointed at localhost.在发展过程中,我已经指出在localhost。The problem is that whenever it hits a "https://" url it doesn't load.现在的问题是,它击中一个“https://”开头的网址时,它不会加载。 When I load the url in mobile safari I get this popup:当我移动Safari浏览器中的URL,我得到这个弹出: ![]() Is there a way to override this with the UIWebView to allow the unverified url?有没有办法覆盖的UIWebView允许未验证的URL吗? |
If it's just for testing during development you can create a category on NSURLRequest and override the following private method:如果它只是用于测试在开发过程中,您可以创建一个类NSURLRequest覆盖下面的私有方法:
@interface NSURLRequest (NSURLRequestWithIgnoreSSL)
+(BOOL)allowsAnyHTTPSCertificateForHost:(NSString*)host;[/code]
@end
@implementation NSURLRequest (NSURLRequestWithIgnoreSSL)
+(BOOL)allowsAnyHTTPSCertificateForHost:(NSString*)host
{
return YES;
} @end[/code]
Just remember to remove it before you submit the app, or Apple will reject it for private API violation.只要记住将其删除,然后再提交的应用程序,苹果将拒绝为私有API违反。
There's a way to do this legally (by App Store laws at least).有一个合法的方式来做到这一点(至少App Store的法律)。 When
you use the NSURLConnection there are 2 methods that can be used to allow self-signed SSL certificates to be used:当您使用NSURLConnection的,可以被用来允许使用自签名SSL证书的有2种方法:
How
to use NSURLConnection to connect with SSL for an untrusted cert? 如何使用NSURLConnection的与SSL连接为一个不受信任的证书吗?
If you implement UIWebViewDelegate use the如果你实现UIWebViewDelegate使用
[code]- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType;[/code]
Return NO to this so that the WebView doesn't load on its own.不返回任何这样的WebView不加载自己的。 Then
construct an NSURLConnection (which can be used with unsigned certificates via the above link).然后构建一个NSURLConnection(可以使用未签名的证书,通过上面的链接)。
Of course the usual SSL recommendations apply here:当然,通常的SSL建议适用于在这里:
-Don't use an unsigned cert on production servers! - 不要在生产服务器上使用未签名的证书!
-Always surface a warning letting your user decide whether to accept the cert or not.总是面让用户决定是否接受该证书或警告。
相关文章推荐
- Android系统在超级终端下必会的命令大全
- Android实战技巧:消息循环与Looper
- android 设备唯一码的获取,Cpu号,Mac地址
- Android Audio System 之一:AudioTrack如何与AudioFlinger交换音频数据
- Android 获取唯一设备号和机型信息
- Android 控制ScrollView滚动到底部
- Android 百度API调用
- 关于《IOS开发基础教程》第九章President.plist的问题
- android之小熊天气(2)界面粗略布局
- 几个不错的APP网站。
- 【Unity3D】【NGUI】处理Button的按下状态?
- android 查询数据库
- 【Unity3D】【NGUI】渐变label
- 模块编译Android源码方法
- 获取android手机序列号
- 编写高质量的Objective-C代码
- cocos2d-x2.2以上版本 win/mac 安装步骤
- 获得Android设备的唯一序列号(一)
- iOS小技巧:禁止全屏点击事件
- Android调用WI-FI的核心代码