Opening URL in an Xcode build

I think it is a bit hard for us to help you without seeing what you are actually doing.

I did have a quick look around and found you can use the navigation policies from the WKNavigationDelegate

I looked at and adapted this

You will need to write this correctly , I just hacked the below to get it to work

  func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: (WKNavigationActionPolicy) -> Void) {
 
        if navigationAction.navigationType == WKNavigationType.linkActivated {
          
            let url = navigationAction.request.url
            let shared = UIApplication.shared
 
            if shared.canOpenURL(url!) {
               // shared.openURL(url!)
                shared.open((url ?? URL(string: "\(url?.absoluteString ?? "")"))!, options: [:], completionHandler: nil)
            }

          decisionHandler(WKNavigationActionPolicy.cancel)
            return
        }

        decisionHandler(WKNavigationActionPolicy.allow)
    }

xcode
openWindowTest.zip (350.2 KB)

hype
OpenUrlsTest1.hype.zip (13.3 KB)


But for iOS I would not use this in the first place. I would use the postMessage from the Hype page to the iOS app.

Also to be able to get back to the app rather than be taken out of it I would use SafariServices.

xcode
OpenUrlsTest2.zip (356.2 KB)

hype
OpenUrlsTest2.hype.zip (13.6 KB)

1 Like