Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I programmatically determine if a URL is a Universal Link or just a regular web URL?

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?

like image 241
Andrew Paul Simmons Avatar asked Jan 10 '17 22:01

Andrew Paul Simmons


1 Answers

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 
                                 }
                             }];
like image 129
Andrew Paul Simmons Avatar answered Nov 15 '22 21:11

Andrew Paul Simmons