iOS Swift 项目中的 UIWebView 显示白屏并输出 "error in __connection_block_invoke_2: Connection interrupted"

UIWebView in iOS Swift project give a white screen and the output "error in __connection_block_invoke_2: Connection interrupted"

我对一个非常简单的 iOS Swift 项目有疑问。目的是让它通过 UIWebView(最终是 Crosswalk)加载 URL。我的代码如下:

import UIKit
import WebKit

class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()

        let myWebView:UIWebView = UIWebView(frame: CGRectMake(0, 0, UIScreen.mainScreen().bounds.width, UIScreen.mainScreen().bounds.height));       
        let url = NSURL (string: "https://www.www.google.com/");
        let requestObj = NSURLRequest(URL: url!);
        myWebView.loadRequest(requestObj);
        self.view.addSubview(myWebView);
    }

    override func prefersStatusBarHidden() -> Bool {
        return true
    }
}

当它运行时(iOS 9.3.4 在 iPod Touch 第 6 代 16b 上,如果这很重要),它会显示一个全白的屏幕并停在那里。片刻之后,Xcode 输出 window 显示:

error in __connection_block_invoke_2: Connection interrupted

谁能告诉我我做错了什么?代码看起来还好吗?也许我设置不正确?我环顾四周,每个人都有不同的答案,但 none 似乎是我的问题。

我对 iOS 和 Swift 开发知之甚少,所以如果这是一个微不足道的问题,我深表歉意,但如果能提供任何帮助,我将不胜感激。

我不知道你是否将 TransportSecurity 添加到你的 info.plist 如果没有将这样的代码行添加到你的项目,因为从 ios 9 apple 更改 TransportSecurity 然后在你的代码中你有 2 [= “https://www.www.google.com/”中的 16=] 我修复了它并检查了它,它就像魅力一样工作

  <key>NSAppTransportSecurity</key>
 <dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSExceptionDomains</key>
<dict>
    <key>your.URL.come</key>
    <dict>
        <key>NSExceptionAllowsInsecureHTTPLoads</key>
        <true/>
        <key>NSIncludesSubdomains</key>
        <true/>
    </dict>
</dict>