wkwebview still not handling universal link

Mobile Technologies Mobile Computing 2 years ago

0 1 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating
_x000D_ _x000D_ I have an iOS universal link targeted at myApp. When I click that link in another app, myApp opens and displays the right payoff perfectly, it's working. But myApp includes a built-in browser using WKWebView. When I click the same universal link from within my built-in browser, iOS doesn't send the link to myApp, it goes and fetches a webpage. Apple docs say If you instantiate a SFSafariViewController, WKWebView, or UIWebView object to handle a universal link, iOS opens your website in Safari instead of opening your app. However, if the user taps a universal link within an embedded SFSafariViewController, WKWebView, or UIWebView object, iOS opens your app. I note this similar question where the suggestion was to define a WKWebView delegate. I have both WKWebView delegates defined and in use in myApp, and it's not helping. This other question has lots of upvotes but no answers. My WKWebView can actually open universal links to other apps. If I click the link https://open.spotify.com/artist/3hv9jJF3adDNsBSIQDqcjp from within the myApp WKWebView then it opens the spotify app without opening any intermediate webpage (even though the long-press menu in myApp doesn't offer to "open in spotify"). But iOS will not deliver the universal link to myApp when I click it from within myApp. After much testing, I discover that I can prevent the display of a webpage associated with the universal link by looking for the specific URL and cancelling the display: func webView(webView: WKWebView, decidePolicyForNavigationResponse navigationResponse: WKNavigationResponse, decisionHandler: (WKNavigationResponsePolicy) -> Void) { if let urlString = navigationResponse.response.URL?.absoluteString { if urlString.hasPrefix(myULPrefix) { // it's a universal link targetted at myApp decisionHandler(.Cancel) return } } decisionHandler(.Allow) } I have to do this in the decision handler for the response, not the one for the action. When I do this, the universal link is queued for delivery to myApp. BUT it is not actually delivered by iOS until I quit my app (for example, by hitting the home button) and relaunch it. The appDelegate function specified as delivering this message in the Apple docs referenced above func application(application: UIApplication, continueUserActivity userActivity: NSUserActivity, restorationHandler: ([AnyObject]?) -> Void) -> Bool {} is not called. It is called when I do a more conventional deeplink - clicking a universal link in Safari to open myApp. Is this a bug? Or a feature? Or am I, as usual, just barking up the wrong tree? Thanks!

Posted on 16 Aug 2022, this text provides information on Mobile Computing related to Mobile Technologies. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (1)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago
_x000D_ This will be the behavior if your wkwebview wep page domain name is same as your universal link domains name. In shot, If web page opened in Safari,SFSafariVC, WKWebView or UIWebView has domain same as your app's app link (universal link) domain it will not tirgger universal link,

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.

Important Mobile Technologies Links