美文网首页
iOS 自建证书不受苹果官方信任,使用wkWebView访问Ht

iOS 自建证书不受苹果官方信任,使用wkWebView访问Ht

作者: 一如初见丿 | 来源:发表于2018-06-25 10:33 被阅读15次

    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

            }

        }

    }

    相关文章

      网友评论

          本文标题:iOS 自建证书不受苹果官方信任,使用wkWebView访问Ht

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