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

大家是否在平时开发中用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网页了!

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容