0

Quick question, have been looking around for hours, but can't really find the answer.

I am trying to open a link in safari with swift. The link opens, but the page stays blank.

func webView(_ webView: WKWebView, createWebViewWith configuration: WKWebViewConfiguration, for navigationAction: WKNavigationAction, windowFeatures: WKWindowFeatures) -> WKWebView? {
        if navigationAction.targetFrame == nil {
            //webView.load(navigationAction.request)
            UIApplication.shared.open(navigationAction.request.url!, options: [:], completionHandler: nil)
        }
        return nil
    }

What am I doing wrong here? Am I missing something in my plist?

Your input is highly appreciated.

I have been learning swift for a few weeks now, but this problem has been kicking my ass for a while now.

Kind Regards,

Wesley

Wesley Schravendijk
  • 483
  • 2
  • 6
  • 21
  • try this may be it helps you :[openURL was deprecated in iOS 10.0: Please use openURL:options:completionHandler](https://stackoverflow.com/questions/42389649/openurl-was-deprecated-in-ios-10-0-please-use-openurloptionscompletionhandl/42389776#42389776) – Anbu.Karthik Oct 25 '19 at 07:25
  • Thank you for your quick response; have tried that, but didn't:t work. Keeps resolving in a blank page – Wesley Schravendijk Oct 25 '19 at 07:28
  • First of all, please confirm that your url is displayed properly in the browser, and then you are successful under the `completionHandler ` debugging. If it is successfully opened or blank, will it be that the page is too large to be loaded, the network reason? – Nullable Oct 25 '19 at 11:54

2 Answers2

0

I found the problem, I was building it on a simulator.

This doesn't work on a simulator. On a real device it seems to work like it should.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Wesley Schravendijk
  • 483
  • 2
  • 6
  • 21
-1

guard let url = URL(string: "https://stackoverflow.com") else { return } UIApplication.shared.open(url)