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);
? ? ? ? }
? ? });
}