如何解决completionHandler was not called error in xcode

How to solve completionHandler was not called error in xcode

我正在使用以下功能在 xcode 中使用 URLSessionDelegate

执行手动服务器身份验证
  func webView(_ webView: WKWebView, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
        func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
            #if DEBUG
            if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust {
                if challenge.protectionSpace.host == "localhost" {
                    // At this point you can prevent a domain that is pretending to be a trusted domain by challenging the user to present some credentials or a security mechanism for authentication.
                    if let serverTrust = challenge.protectionSpace.serverTrust {
                        let credential = URLCredential(trust: serverTrust)
                        completionHandler(URLSession.AuthChallengeDisposition.useCredential, credential)
                    }
                }
            }

                      #endif
        }
    }

但我仍然收到此错误 => 由于未捕获的异常 'NSInternalInconsistencyException' 而终止应用程序,原因:'未调用传递给 -[health.ViewController webView:didReceiveAuthenticationChallenge:completionHandler:] 的完成处理程序。如果有人知道如何解决这个问题请告诉我

如果启用了调试,您只会调用完成块。每次调用委托方法时,您都必须调用完成处理程序块,并且对于每个保护 space——通常是通过请求默认处理。如果您调用失败,会话将永远等待您调用该块。