某些网站未在Swift Xcode 9.2中加载

时间:2019-04-24 11:37:02

标签: ios swift xcode web

嘿:)我是新手,我想创建一个WebView App。如果我将URL设置为https://www.apple.com,则可以正常使用。但是,如果我将UR1更改为https://www.berkearas.de,它将不再起作用。该网站仍在运行并且在线,我也有SSL证书。我能做什么?谢谢大家:)

import WebKit
class ViewController: UIViewController, WKUIDelegate {

    var webView: WKWebView!

    override func loadView() {
        let webConfiguration = WKWebViewConfiguration()
        webView = WKWebView(frame: .zero, configuration: webConfiguration)
        webView.uiDelegate = self
        view = webView
    }
    override func viewDidLoad() {
        super.viewDidLoad()

        let myURL = URL(string:"https://www.berkearas.de")
        let myRequest = URLRequest(url: myURL!)
        webView.load(myRequest)
    }}

1 个答案:

答案 0 :(得分:1)

只需将NSAppTransportSecurity键添加到您的.plist文件中,然后一切正常即可。

<key>NSAppTransportSecurity</key>  
 <dict>  
      <key>NSAllowsArbitraryLoads</key><true/>  
 </dict>

Screenshot