我在使用WKWebView中的WebSockets时遇到自签名证书的问题.我一直收到以下错误,不确定如何去做:
WebSocket network error: The operation couldn’t be completed. (OSStatus error -9807.)
Run Code Online (Sandbox Code Playgroud)
作为临时修复,我试图通过在我的WKWebView中实现此委托函数来允许未经验证的ssl证书:
func webView(webView: WKWebView, didReceiveAuthenticationChallenge challenge: NSURLAuthenticationChallenge,
completionHandler: (NSURLSessionAuthChallengeDisposition, NSURLCredential?) -> Void) {
let cred = NSURLCredential.init(forTrust: challenge.protectionSpace.serverTrust!)
completionHandler(.UseCredential, cred)
}
Run Code Online (Sandbox Code Playgroud)
这段代码允许我绕过SSL错误来加载页面,但WebSocket连接仍然有错误......有什么想法吗?
| 归档时间: |
|
| 查看次数: |
675 次 |
| 最近记录: |