我正在尝试在iOS的全屏移动应用程序中构建外部网页。一切正常。

但是,如何在Safari中打开外部url(在google.com外部)?

import UIKit
import WebKit

class ViewController: UIViewController {

    @IBOutlet var mWebKit: WKWebView!
    let urlMy = URL(string: "https://www.google.com/")

    override func viewDidLoad() {
        super.viewDidLoad()

        let request = URLRequest(url: urlMy!)
        mWebKit.load(request)
        // Do any additional setup after loading the view.
    }
}


非常感谢你!

最佳答案

func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {


        if navigationAction.targetFrame == nil{

            if #available(iOS 10.0, *) {
                UIApplication.shared.open(navigationAction.request.url!, options: [:])
            } else {
                UIApplication.shared.openURL(navigationAction.request.url!)
                // Fallback on earlier versions
            }
        }
    }

10-07 19:54