美文网首页
WKWebView空白,报错The certificate fo

WKWebView空白,报错The certificate fo

作者: 白牛桑 | 来源:发表于2023-05-18 15:57 被阅读0次

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

            }

        });

    }

    相关文章

      网友评论

          本文标题:WKWebView空白,报错The certificate fo

          本文链接:https://www.haomeiwen.com/subject/uiawsdtx.html