gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 06:33:28 26 4
gpt4 key购买 nike

我在处理一个非常简单的 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
}
}

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

error in __connection_block_invoke_2: Connection interrupted

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

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

最佳答案

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

  <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>

关于ios - iOS Swift 项目中的 UIWebView 显示白屏并输出 "error in __connection_block_invoke_2: Connection interrupted",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39650787/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com