
类似地,NSURLConnection提供了实施者首先决定如何检查证书的能力,然后在失败的情况下决定如何执行,因此在这种情况下也可以向用户显示警告并为他们提供继续加载的机会页面还是不.
但是,当在UIWebVIEw中加载https页面时,似乎无法通过证书检查行为只是无法加载页面 – dIDFailLoaDWithError:使用kcfURLErrorServerCertificateUntrusted调用,但是没有任何内容显示给用户.
这是不一致的 – UIWebVIEw行为应该以类似于Safari的方式在iPhone本身中保持一致吗?
它也是一个尴尬,NSURLConnection允许这个NSURLRequest的完全灵活性:setAllowsAnyhttpSCertificate是私有的.
有没有办法实现与Safari一致的行为,这个默认行为可以像NSURLConnection一样的定制吗?
干杯
附:
请不要光顾侧面的讨论,为什么有人想这样做,非常感谢.
1)当页面被加载时,它将失败,因此添加一些类似以下的内容来执行以下 *** 作:FalseLoaDWithError:
- (voID)webVIEw:(UIWebVIEw *)webVIEw dIDFailLoaDWithError:(NSError *)error if ([error.domain isEqualToString: NSURLErrorDomain]) { if (error.code == kcfURLErrorServerCertificateHasBadDate || error.code == kcfURLErrorServerCertificateUntrusted || error.code == kcfURLErrorServerCertificateHasUnkNownRoot || error.code == kcfURLErrorServerCertificateNotYetValID) { display dialog to user telling them what happened and if they want to proceed 2)如果用户要加载页面,则需要使用NSURLConnection进行连接:
NSURLRequest *requestObj = [NSURLRequest requestWithURL:self.currentURL cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:10.0];self.loadingUnvalIDatedhttpSPage = YES;[self.webVIEw loadRequest:requestObj];
3)然后将此更改为shouldStartLoaDWithRequest
- (BOol)webVIEw:(UIWebVIEw *)webVIEw shouldStartLoaDWithRequest:(NSURLRequest *)request navigationType:(UIWebVIEwNavigationType)navigationType { if (self.loadingUnvalIDatedhttpSPage) { self.connection = [[NSURLConnection alloc] initWithRequest:request delegate:self]; [self.connection start]; return NO; } 4)实现NSURLConnectionDelegate为:
- (voID)connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge{ SecTrustRef trust = challenge.protectionSpace.serverTrust; NSURLCredential *cred; cred = [NSURLCredential credentialForTrust:trust]; [challenge.sender useCredential:cred forAuthenticationChallenge:challenge];}- (voID)connection:(NSURLConnection *)connection dIDReceiveResponse:(NSURLResponse *)response;{ NSURLRequest *requestObj = [NSURLRequest requestWithURL:self.currentURL cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:10.0]; self.loadingUnvalIDatedhttpSPage = NO; [self.webVIEw loadRequest: requestObj]; [self.connection cancel];} 这一切似乎都很好.
总结以上是内存溢出为你收集整理的ios – 有没有人使用UIWebView找到一种使用无效服务器证书加载HTTPS页面的方法?全部内容,希望文章能够帮你解决ios – 有没有人使用UIWebView找到一种使用无效服务器证书加载HTTPS页面的方法?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)