Stop WKWebView redirecting to another app based on Universal link

Viewed 1306

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.

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

    decisionHandler(WKNavigationActionPolicy(rawValue: WKNavigationActionPolicy.allow.rawValue + 2)!)
}

This seems to solve the issue.

hopefully WKWebView custom agent works for you. use following code

webView.customUserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.95 Safari/537.36" 
Related