最近收到了个新的需求,电脑自己开一个服务(https协议)。手机端使用webView加载呈现。
而在实现时遇到了:Https服务器证书无效 code = -1202
Log
最后决定不验证证书先做实现与测试:
//WKWebView与UIWebView代理不同,需使用NSURLConnectionDelegate
@interface ViewController ()<WKNavigationDelegate,NSURLConnectionDelegate>
#pragma mark -- NSURLConnectionDelegate
- (void)webView:(WKWebView *)webView didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential * _Nullable))completionHandler{
NSURLCredential *card = [[NSURLCredential alloc] initWithTrust:challenge.protectionSpace.serverTrust];
completionHandler(NSURLSessionAuthChallengeUseCredential,card);
}
做个记录