您需要添加异常(
SecTrustSetExceptions
)对于特定的url。因为它的签名身份和您的
WKWebView
.
我在我的应用程序中也遇到了同样的问题,并通过使用下面的代码片段成功地解决了这个问题。
extension PaymentWebViewController: WKNavigationDelegate {
func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
decisionHandler(.allow)
}
func webView(_ webView: WKWebView, decidePolicyFor navigationResponse: WKNavigationResponse, decisionHandler: @escaping (WKNavigationResponsePolicy) -> Void) {
decisionHandler(.allow)
}
func webView(_ webView: WKWebView, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
let serverTrust = challenge.protectionSpace.serverTrust
let exceptions = SecTrustCopyExceptions(serverTrust!)
SecTrustSetExceptions(serverTrust!, exceptions)
completionHandler(.useCredential, URLCredential(trust: serverTrust!))
}
}
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoadsInWebContent</key>
<true/>
</dict>