美文网首页
iOS开发---WKWebView加载不受信任的https -O

iOS开发---WKWebView加载不受信任的https -O

作者: BmBN666 | 来源:发表于2019-01-02 17:21 被阅读0次

在plist文件中设置Allow Arbitrary Loads in Web Content 置为 YES,并实现wkwebView下面的代理方法

oc:

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

}

swift:

func webView(_ webView: WKWebView, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {

        if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust{

            let card:URLCredential = URLCredential.init(trust: challenge.protectionSpace.serverTrust!)

            completionHandler(URLSession.AuthChallengeDisposition(rawValue:2)!,card)

        }

    }

原文:https://blog.csdn.net/wz_yinglong/article/details/77507262

相关文章

网友评论

      本文标题:iOS开发---WKWebView加载不受信任的https -O

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