NSURLErrorDomain Code=-1202 "The certificate for this server is invalid. You might be connecting to a server that is pretending to be “192.168.1.159” which could put your confidential information at risk."
class BaseWebViewController:BaseViewController,WKUIDelegate,WKNavigationDelegate,NSURLConnectionDelegate {
// MARK: - NSURLConnectionDelegate
func webView(_ webView: WKWebView, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
//后端证书认证
if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust {
#if PRODUCTION
#else
//测试环境下 创建凭据对象 信任证书
let card = URLCredential.init(trust: challenge.protectionSpace.serverTrust!)
completionHandler(URLSession.AuthChallengeDisposition.useCredential,card)
#endif
}
}
}