大家是否在平時(shí)開發(fā)中用WKWebView加載HTTPS網(wǎng)頁加載不出來譬挚?如果來請仔細(xì)閱讀這篇文章,它會(huì)告訴你解決放肮ッ獭揩魂!
遵守WKWebView的二個(gè)代理分別是
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網(wǎng)頁了!