"成功"HTTPS NSURLRequest后WKWebView为空白

the*_*ude 7 https uiwebview ios swift wkwebview

我创建了一个NSURLRequest(HTTPS)

WKWebView的委托回调成功返回,没有错误.

'decisionPolicyForNavigationAction'随决策处理程序中的Allow Enum一起提供

   @available(iOS 8.0, *)
    func webView(webView: WKWebView, decidePolicyForNavigationAction navigationAction: WKNavigationAction, decisionHandler: (WKNavigationActionPolicy) -> Void) {

        decisionHandler(.Allow)

    }
Run Code Online (Sandbox Code Playgroud)

并且didReceiveAuthChallenge按原样处理:

@available(iOS 8.0, *)
func webView(webView: WKWebView, didReceiveAuthenticationChallenge challenge: NSURLAuthenticationChallenge,
    completionHandler: (NSURLSessionAuthChallengeDisposition, NSURLCredential?) -> Void) {
        let cred = NSURLCredential.init(forTrust: challenge.protectionSpace.serverTrust!)
        completionHandler(.UseCredential, cred)
        print("Did receive auth challenge")
}
Run Code Online (Sandbox Code Playgroud)

因为'didFinishNavigation'我不确定因为我的WebView仍然是空白而导致错误后没有错误?如果我使用UIWebView我得到正确的网页显示?

干杯,

Ror*_*nel 7

要检测错误,您应该确保实现didFailNavigation:withErrordidFailProvisionalNavigation:withError.

从有效的链接,它们似乎是https URL.没有的是http URL.实现上述错误方法应该告诉你出了什么问题.

iOS9中有一个新的安全功能,除非服务器符合特定的规则集,或者您设置xcode以覆盖新功能,否则无法加载HTTP URL.您可以通过将以下内容添加到Info.plist文件中来覆盖新功能.只需在底部粘贴以下内容:

<key>NSAppTransportSecurity</key>  
<dict> 
   <key>NSAllowsArbitraryLoads</key><true/>  
</dict> 
Run Code Online (Sandbox Code Playgroud)

这会覆盖所有新功能.但是,您可以执行更具体的覆盖.有关更改的Apple技术说明如下:https://developer.apple.com/library/prerelease/ios/technotes/App-Transport-Security-Technote/index.html