【发布时间】:2020-10-02 08:02:21
【问题描述】:
我在 Mac 应用程序中打开 webApplication,打开 webApplication 我使用 webView.load 方法在 webView 中显示内容。大多数时候能够加载内容,但有时会抛出授权失败错误。这是一个间歇性问题。
func webView(_ webView: WKWebView, decidePolicyFor navigationResponse: WKNavigationResponse,
decisionHandler: @escaping (WKNavigationResponsePolicy) -> Void) {
if let response = navigationResponse.response as? HTTPURLResponse {
print("Response: \(response)")
if response.statusCode == 401 {
使用 AppleConnect 单点登录的 Web 应用程序。
func webView(_ webView: WKWebView, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
if let serverTrust = challenge.protectionSpace.serverTrust {
completionHandler(URLSession.AuthChallengeDisposition.performDefaultHandling, URLCredential(trust: serverTrust))
//completionHandler(URLSession.AuthChallengeDisposition.performDefaultHandling, nil)
}
}
此错误仅在 Big Sur 操作系统中出现,而不是在 Catalina 中,这是一个不连续的间歇性问题。以前有人遇到过这个问题吗?
【问题讨论】:
标签: swift cocoa cocoa-touch wkwebview http-status-code-401