Universal links not working in WKWebView

I have web-view based app and other native apps in company. We were using universal links to redirect user to other apps when needed (other apps still support universal links - I can run them by pressing links from Apple Notes app).

We recently made a transition to WKWebView (from UIWebView), which provides a way better experience. But after the update Universal Links stopped working and we cannot start other apps when user press link inside our app.


According to the docs:

"Universal links let iOS 9 users open your app when they tap links to your website within WKWebView and UIWebView views and Safari pages, in addition to links that result in a call to openURL:, such as those that occur in Mail, Messages, and other apps." (https://developer.apple.com/library/ios/documentation/General/Conceptual/AppSearch/UniversalLinks.html)


It seems that WKWebView is not handling the Universal Links. My questions is, am I missing some special configuration for WKWebView or this is WebKit bug? I'm creating web view as provided:


WKWebViewConfiguration *config = [[WKWebViewConfiguration alloc] init];
config.allowsInlineMediaPlayback = YES;
config.processPool = // Here I'm using shared process pool

self.webView = [[WKWebView alloc] initWithFrame:CGRectZero configuration:config];
self.webView.translatesAutoresizingMaskIntoConstraints = NO;
self.webView.clipsToBounds = YES;
self.webView.allowsBackForwardNavigationGestures = YES;

if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"9.0")) {
  self.webView.allowsLinkPreview = YES;
}
[self addSubview:_webView];


To show the problem I have created simple repository with simple app (https://github.com/apan06/UniversalLinks - with very simple initialisation). There are two web views - WKWebView and UIWebView with both with simple html that there is only link to Twitter. WKWebView simply loads the Twitter page. On the other hand UIWebView open Twitter app. Just remembet:

- test it on device with Twitter app installed, if you don't have Twitter app or don't like Twitter you can chande link

- I was testing it on iPhone 6 with iOS 9.2.1


Thanks!

Replies

Hello, just bumped to this issue. Did you manage to solve it?

Stuck on this issue as well! Bump.

Also having the same issue in iOS 10. Solution?

Hey dude have you got any solution?

Having the same issue.


Works on my iOS 10.1.1 iphone, but not on my 10.3.1 device.

Doesn't work for me either using iOS 15. Put a hacky solution which doesn't always work:

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

        if let url = navigationAction.request.url, !UIApplication.shared.canOpenURL(url) {

            UIApplication.shared.open(url)

            decisionHandler(.cancel)

            return

        }

        decisionHandler(.allow)

}