Xcode 9 WebKit不加载外页

时间:2017-12-14 20:47:56

标签: ios xcode

我在我的应用程序中使用此代码来加载网站但是它不允许我在我的网站中打开外部链接。例如,如果您点击Facebook,它什么都不做。有什么建议?

import UIKit
import WebKit
class ViewController: UIViewController, WKUIDelegate {
@IBOutlet weak var webViewContainer: UIView!
var webView: WKWebView!

  override func viewDidLoad() {
    super.viewDidLoad()
    let webConfiguration = WKWebViewConfiguration()
    let customFrame = CGRect.init(origin: CGPoint.zero, size: CGSize.init(width: 0.0, height: self.webViewContainer.frame.size.height))
    self.webView = WKWebView (frame: customFrame , configuration: webConfiguration)
    webView.translatesAutoresizingMaskIntoConstraints = false
    self.webViewContainer.addSubview(webView)
    webView.topAnchor.constraint(equalTo: webViewContainer.topAnchor).isActive = true
    webView.rightAnchor.constraint(equalTo: webViewContainer.rightAnchor).isActive = true
    webView.leftAnchor.constraint(equalTo: webViewContainer.leftAnchor).isActive = true
    webView.bottomAnchor.constraint(equalTo: webViewContainer.bottomAnchor).isActive = true
    webView.heightAnchor.constraint(equalTo: webViewContainer.heightAnchor).isActive = true
    webView.uiDelegate = self

    let myURL = URL(string: "https://gracekutztown.weebly.com")
    let myRequest = URLRequest(url: myURL!)
    webView.load(myRequest)
  }
}

0 个答案:

没有答案