On iOS, how can I programmatically determine if a URL is a Universal Link or just a regular web URL?
Let's say you are about to launch the URL http://www.yelp.com from your own iOS app. (http://www.yelp.com is a fully registered universal link.)
Case one) the user doesn't have the app installed -> You want to show them the website in an IN-APP webview.
Case two) the user does have the app installed -> You want to launch out of your app and deep link directly to the the yelp app by using [[UIApplication sharedApplication] openURL:URL]; instead of presenting a webview in app.
Here is the problem: All you get to work with is the string url: "http://www.yelp.com" Your goal is to launch out to the yelp app if installed but present an in-app webview if yelp is not installed.
Note 1: This question is only about universal links. Please do not give answers which use URL Schemes.
Note 2: This question is not about specifically launching the yelp app. The solution should work for any url to determine if it is a universal link of an installed app.
Can you do this?
Detect if a link is universal using UIApplicationOpenURLOptionUniversalLinksOnly
Following is the solution:
[[UIApplication sharedApplication] openURL:url
options:@{UIApplicationOpenURLOptionUniversalLinksOnly: @YES}
completionHandler:^(BOOL success){
if(!success) {
// present in app web view, the app is not installed
}
}];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With