NSURLConnection 在 Swift 4 中完成并出现错误 - 代码 -1100

0 nsurlconnection swift

我想在没有 https 的情况下在 webview 中打开给定的 url(例如 myDomain.com)。我得到了

NSURLConnection 已完成,但出现错误 - 代码 -1100

Android 上快速打开 url 时出错。我该怎么做?

let url = URL(string: "myDomain.com")

webView.loadRequest(URLRequest(url: url!))
Run Code Online (Sandbox Code Playgroud)

hen*_*dmg 5

自 WWDC 2015 起,Apple 不再允许纯 HTTP 请求。但是您可以禁用此限制。您需要将其添加到您的Info.plist文件中:

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

(要将文件作为源代码打开,只需右键单击它并选择“打开为”)