Nam
Nam

Reputation: 1876

Open web if app is not installed

Say, on my iPhone I would like to open our web page, if I dont have the app installed. Yes, I know about Universal Links by Apple, but this only works for iOS devices and they have to run iOS 9.

And just to be sure, this can be done. I've seen it on Ebay. If you have a link it will open in the app, if installed, or in a browser regardless of device and version:

http://rover.ebay.com/rover/0/e11011.m43.l1123/7?euid=b4a2e0009e73485c9f8b740ae229dba1&bu=43989098353&loc=http%3A%2F%2Fwww.ebay.com%2Fulk%2Fitm%2F162076993293&sojTags=bu=bu

Upvotes: 0

Views: 2547

Answers (1)

Alex Bauer
Alex Bauer

Reputation: 13633

To be honest, this is kind of a pain to implement on your own. There is no easy way to handle everything without a ton of nasty edge cases, most notably the 'Cannot Open Page" error users will see if they don't have your app installed. Until iOS 9, a reasonable basic implementation was putting a JavaScript redirect like this into a dedicated redirect page on your site:

setTimeout(function() {
  window.location = "https://yourdomain.com";
}, 25);

// If "yourapp://" is registered, the user will see a dialog
// asking if they want to open your app. If they agree, your
// app will launch immediately and the timer won't fire.
// If not installed, you'll get an ugly "Cannot Open Page" 
// dialogue and your fallback page will open when the timer expires.

window.location = "yourapp://";

Unfortunately this would still show a 'Cannot Open Page' error, but until recently it was possible to get around this in a reasonably user-friendly way by using a more nuanced version of this script. Sadly, Apple intentionally broke that with the iOS 9.2 update, so custom URL schemes are actually pretty much useless for deep linking now, unless you are certain the app is already installed on that device. Apple is obviously trying to push Universal Links adoption as much as possible.

The best solution is a combination of custom URL scheme links (with intelligent JavaScript redirections) and Apple's new Universal Links. Universal Links let you use a normal http:// URL to a page on your website (the page could be a simple redirection to your desired fallback webpage without the custom URL trigger that causes the 'Cannot Open Page' error), which is intercepted by your phone and sent directly into your app if installed. Unfortunately (as you noted) Universal Links only work in iOS 9+ and don't work yet when opened inside a lot of apps, so a lot of edge case handling is needed to get a solid experience for every user.

This is quite a lot to handle, so the best option might be a free service like Branch.io (full disclosure: I work with the team) to take care of all the technical aspects. You can find examples of apps using the Branch service (including several from eBay) here.

Upvotes: 3

Related Questions