ios中wkWebview加载异常

APP中有一个h5页面突然无法加载 ,断点后打印
The certificate for this server is invalid. You might be connecting to a server that is pretending to be “*****” which could put your confidential information at risk.
此服务器的证书无效。您可能正在连接到假装为“****”的服务器,这可能会使您的机密信息面临风险。
其实这个问题 换成https就好了,奈何条件不允许。
最终解决方案添加下方代码

  • (void)webView:(WKWebView *)webView didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *credential))completionHandler {
    NSLog(@“Allowing all”);
    SecTrustRef serverTrust = challenge.protectionSpace.serverTrust;
    CFDataRef exceptions = SecTrustCopyExceptions (serverTrust);
    SecTrustSetExceptions (serverTrust, exceptions);
    CFRelease (exceptions);
    completionHandler (NSURLSessionAuthChallengeUseCredential, [NSURLCredential credentialForTrust:serverTrust]);
    }

你可能感兴趣的:(iOS问题汇总,wkwebview,iOS)