WKWebView空白,报错The certificate for this server is invalid

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

        }

    });


}

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