Search code examples
iosswiftwkwebviewservicenow

Stop WKWebView redirecting to another app based on Universal link


We are using WKWebview to custom load and manage our ServiceNow instance, but however while login succeeds, if user has "ServiceNow" mobile app installed post login it opens ServiceNow app.

Tried blocking the final Url navigation action(decidePolicyfor navigationAction) without success.

It's happening due to Universal link at ServiceNow end. http://service-now.com/apple-app-site-association

Any ways to block this operation at our end.


Solution

  • func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
    
        decisionHandler(WKNavigationActionPolicy(rawValue: WKNavigationActionPolicy.allow.rawValue + 2)!)
    }
    

    This seems to solve the issue.