iOS -- WKWebView显示空白,报错:"The certificate for this server is invalid. You might be connecting to a se
解决方法在wkUIDelegate设置
#pragma mark - wk代理(UIDelegate)
- (void)webView:(WKWebView *)webView didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential * _Nullable))completionHandler{
// 信任过期证书
dispatch_async(dispatch_get_main_queue(), ^{
if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {
if(challenge.previousFailureCount==0) {
NSURLCredential*credential = [NSURLCredentialcredentialForTrust:challenge.protectionSpace.serverTrust];
completionHandler(NSURLSessionAuthChallengeUseCredential, credential);
}else{
completionHandler(NSURLSessionAuthChallengeUseCredential,nil);
}
}else{
completionHandler(NSURLSessionAuthChallengeUseCredential, nil);
}
});
}