iOS 自建证书不受苹果官方信任,使用wkWebView访问Htttps 错误 NSURLErrorDomain Code=-1202 certificate invali

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 
#if PRODUCTION
#else
func webView(_ webView: WKWebView, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
        if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust {
            let card = URLCredential.init(trust: challenge.protectionSpace.serverTrust!)
            completionHandler(URLSession.AuthChallengeDisposition.useCredential,card)
        }

    }

#endif


猜你喜欢

转载自blog.csdn.net/weiwandaixu_/article/details/80797926
今日推荐