8

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.

ibiren
  • 673
  • 6
  • 25

2 Answers2

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

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

This seems to solve the issue.

ibiren
  • 673
  • 6
  • 25
  • 1
    the solution is working . will you please explain why it is working ??? – Return Zero Apr 20 '19 at 09:14
  • This works because of this: `static const WKNavigationActionPolicy WK_API_AVAILABLE(macos(10.11), ios(9.0)) _WKNavigationActionPolicyAllowWithoutTryingAppLink = (WKNavigationActionPolicy)(WKNavigationActionPolicyAllow + 2);` https://github.com/WebKit/WebKit/blob/995f6b1595611c934e742a4f3a9af2e678bc6b8d/Source/WebKit/UIProcess/API/Cocoa/WKNavigationDelegatePrivate.h#L61 It's a private navigation policy declared that skips the deeplinking. – txulu Nov 23 '21 at 14:07
0

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" 
Return Zero
  • 424
  • 4
  • 15