iOS wkwebview https 加载不受信用的站点

2019-09-19 14:25:23 浏览数 (1)

iOS 9.0以上直接设置WKNavigationDelegate代理

代码语言:javascript复制
    func webView(_ webView: WKWebView, didReceive challenge: URLAuthenticationChallenge,
                 completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
        let cred = URLCredential.init(trust: challenge.protectionSpace.serverTrust!)
        completionHandler(.useCredential, cred)
    }

  引用一下

代码语言:javascript复制
self.wk.navigationDelegate = self

  搞定,成功加载证书错误的站点

0 人点赞