iOS HTTPS证书不受信任怎么办

iOS开发安装SSL证书可能会遇到HTTPS证书不受信任的问题,比如一些原因造成wkwebView中某些网址打不开,查看错误是因为服务器证书无效,实际就是不受信任怎么办?

SSL证书申请指南提供的解决方法如下:

在plist文件中将“Allow Arbitrary Loads in Web Content”设置为YES。假如有设置 NSAllowsArbitraryLoads 为 YES,可以不用设置。

接下来输入以下代码:

– (void)webView:(WKWebView *)webView didReceiveAuthenticationChallenge:

(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)

(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential * _Nullable credential))completionHandler{

if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {

NSURLCredential *card = [[NSURLCredential alloc]initWithTrust:challenge.protectionSpace.serverTrust];

completionHandler(NSURLSessionAuthChallengeUseCredential,card);

}

}

SSL证书品牌

相关文章

LAYOUT

SAMPLE COLOR

Please read our documentation file to know how to change colors as you want

BACKGROUND COLOR

BACKGROUND TEXTURE