0

I'm trying to build an external webpage in a fullscreen mobile app in iOS. Everything is working fine.

But how is it possible to open external urls (outside google.com) in Safari?

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

Thank you very much!

Sulthan
  • 128,090
  • 22
  • 218
  • 270

1 Answers1

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

Muhammad Afzal
  • 201
  • 1
  • 9