关于WKWebView加载HTTPS网页不显示的解决方案

2017-03-01  本文已影响0人  你相信奇迹么

大家是否在平时开发中用WKWebView加载HTTPS网页加载不出来?如果来请仔细阅读这篇文章,它会告诉你解决放啊!

遵守WKWebView的二个代理分别是

WKNavigationDelegate,WKUIDelegate

然后在其代理方法

- (void)webView:(WKWebView*)webView didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge*)challenge completionHandler:(void(^)(NSURLSessionAuthChallengeDispositiondisposition,NSURLCredential*credential))completionHandler

里面写上if([challenge.protectionSpace.authenticationMethodisEqualToString:NSURLAuthenticationMethodServerTrust]) {

if([challengepreviousFailureCount] ==0){

NSURLCredential*credential = [NSURLCredentialcredentialForTrust:challenge.protectionSpace.serverTrust];

completionHandler(NSURLSessionAuthChallengeUseCredential, credential);

}else{

completionHandler(NSURLSessionAuthChallengeCancelAuthenticationChallenge,nil);

}

}else{

completionHandler(NSURLSessionAuthChallengeCancelAuthenticationChallenge,nil);

}

这些代码就可以加载HTTPS网页了!

上一篇 下一篇

猜你喜欢

热点阅读