In the Universal Links section of the iOS App Search Programming Guide, Apple says:
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 from within an embedded SFSafariViewController, WKWebView, or UIWebView object, iOS opens your app.
What does "handle a universal link" mean? Can I not ever open the given URL with an SFSafariViewController
, WKWebView
, or UIWebView
? Does it only apply during -[UIApplicationDelegate application:continueUserActivity:restorationHandler:]
, or is there a timeout in place? Does this mean we can't ever open the URL in a SFSafariViewController
, WKWebView
, or UIWebView
?
I'm not sure I fully understand your question.
Just to cover basics, I'll allow Apple to explain what a Universal Link is:
So basically, imagine you're working on a Twitter client, and going through the timeline, you encounter a tweet with the following YouTube video link: https://youtu.be/ejQod8liXm0
If you tap it, since it's an HTTP URL, you'd expect Safari to open the link. However, I think we all iOS developers can pretty much all agree on the fact that native apps are better, so a better user experience would be for the official YouTube app to open the video, even from your third-party client.
This is what "Universal Links" allow; if the YouTube app registers itself on iOS as the app responsible for handling https://www.youtube.com(*) links, everyone in the iOS ecosystem benefits if we follow the API rules. The same thing happens if you run a website and you want any of your content to trigger your official iOS app to open if your user has it installed, or for the user to be prompted if they'd like to install it for a better user experience (and to help your business, of course).
So, with all of this out of the way, let's get back to the original text:
What this means is that, if from your app, your user taps on a Universal Link to your content (example: http://www.your-company.com/foo), and you do not detect this in your app's code via a regular expression for example, and instead instantiate a
SFSafariViewController
,WKWebView
orUIWebView
to open it as if it were a regular link to The New York Times or something, the OS will understand that instead of opening this in your app, you want Safari to handle this for you. Remember: the whole purpose of Universal Links is for the user to get a better experience by having the URL being handled by a native app, not by the browser.This is what the first sentence says. As for the second, it clears up a potential follow-up question: what if the user taps on a Universal Link to my content from an embedded browser from another app that's not mine? Then, the sentence says, the OS will behave normally: it will open your app, respecting Universal Link rules.
TL;DR: You need to detect Universal Links to your content from your app too, in code, and handle them. iOS will not handle this for you. Instead, if you tell the OS to open a Universal Link to your app's content in an embedded browser from your app, it will do exactly as told.
EDIT: If you need help deciding between asking
SFSafariViewController
or the-openURL:options:completitionHandler:
APIs to open a URL, this link should help you; my recommendation would be to use-openURL:options:completitionHandler:
first, and if it's not successful, then useSFSafariViewController
or similar.Hope this helps and that I've correctly understood your question.
Cheers! And Happy iOS 11 programming! :)
I resolved this issue with my Swift 4 class below. It also uses embedded Safari Browser if possible. You can follow a similar method in your case too.