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