WKwebView 在 iOS 应用程序中间歇性地给出错误,WebPageProxy 错误代码为 1003

Roh*_*ale 1 webproxy ios wkwebview

我有 iOS 应用程序,其中有 WKWebview。用于从远程 URL 加载 HTML。我在日志中收到错误

[Process] 0x1550bfe18 - [pageProxyID=42, webPageID=43, PID=1902] WebPageProxy::didFailProvisionalLoadForFrame: frameID = 3, domain = NSURLErrorDomain, code = -1003
Run Code Online (Sandbox Code Playgroud)

按照该didFailProvisionalNavigation方法调用 WKWebview。

这是间歇性发生的。意味着在 WKWebbView 中成功使用网页一段时间,并在一段时间内出现上述错误。

同样的事情在 Android 设备上运行没有任何问题。

  1. 为什么它不总是失败?
  2. 这是iOS应用程序的问题吗?
  3. 这是服务器问题吗?
  4. 服务器出现此错误的原因是什么?
  5. 我需要在服务器上更新哪些配置?

小智 10

处理包含不受信任证书的链接

func webView(_ webView: WKWebView, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
    guard let serverTrust = challenge.protectionSpace.serverTrust else {
        completionHandler(.cancelAuthenticationChallenge, nil)
        return
    }
    let exceptions = SecTrustCopyExceptions(serverTrust)
    SecTrustSetExceptions(serverTrust, exceptions)
    completionHandler(.useCredential, URLCredential(trust: serverTrust));
}
Run Code Online (Sandbox Code Playgroud)