KWWebView与https的激情

2021-05-25  本文已影响0人  斌小狼

最近收到了个新的需求,电脑自己开一个服务(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);
}

做个记录

上一篇 下一篇

猜你喜欢

热点阅读