Redirect to Application If Installed, Otherwise to App Store

Redirect to application if installed, otherwise to App Store

There is no way to check for this.
However, there is a nice workaround.

The idea is basically this:

  1. The first time you open your app, you open up mobile safari from within your app to a predefined URL on your server
  2. On that URL you set up a cookie, like appInstalled to the users mobile safari
  3. You then kick the user back to your app with your registered scheme (same as FB does with SSO)
  4. All your email links point to your website, but on the website you check if the browser is mobile Safari and if the appInstalled cookie exists
  5. If either the browser is not mobile Safari or the cookie is not found, you redirect to the AppStore, or stay in your webpage.
  6. If the conditions of #4 are true, you redirect the user to your app with the registered scheme
  7. If the app has been deleted by the user, so the custom url scheme fails, you have a fail-safe redirect to the appstore

The 2 last steps are explained on this SO post

Redirects to app store if app is not installed

I'm assuming the link you want to pass by email is an https link. If that's the case, for iOS to be able to redirect it to your app, you'll need to implement universal links. This implementation requires you to register the domain you want to respond to on your entitlements file and add an apple-app-site-association file to your backend. This way Apple can verify the domain you're trying to respond to is really yours.

As a result, when the app gets installed, it can be invoked by your domain links via deeplinking.

Now when there's no installed app able to respond to a specific https domain link, the system will simply open it on a web browser. Consequently, you cannot force iOS to open such links on AppStore directly. What you can do is to check whether the running device is iOS when your website gets accessed and ask the system to show your app on AppStore.

And to request iOS to launch AppStore from a website you can use itms-apps:

const iOS = !!navigator.platform && /iPad|iPhone|iPod/.test(navigator.platform);

if (iOS) {
// Just replace `https://` with `itms://` on your app's AppStore link.
window.location.href = "itms://";

// In this example I'm redirecting to Google Maps app page on AppStore.

Note: This is just a simple example used to demonstrate the concept. For a real application, you may want to use a device detection library for browsers, like mobile-detect.js

iOS: opening app with custom URL if installed, itunes otherwise

To be honest, this is kind of a pain to implement on your own. After you've detected the iOS user agent, you could implement a JavaScript redirection on your server something like this:

setTimeout(function() {
window.location = "";
}, 25);

// If "yourapp://" is registered, the user will see a dialog
// asking if 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 the App Store will launch when the timer expires.

window.location = "yourapp://";

Obviously this isn't an ideal solution and it has a ton of nasty edge cases, most notably the 'Cannot Open Page" error users will see before being redirected to the App Store if they don't have your app installed. 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.

You could also enable Universal Links. Apple knows this is an annoying problem and is trying to help. Universal Links let you use a normal URL to a page on your website (which could be a simple redirection to the App Store 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 Universal Links only work in iOS 9+, and don't work yet when opened inside a lot of apps.

The best solution is a combination of the above methods: Universal Links and Applinks everywhere they are supported, and intelligent JavaScript redirections as a fallback. This is quite a lot to handle, so the best option might be a free service like (full disclosure: I work with the team) to take care of all the technical aspects.

Detect if an app is present in IOS else redirect to app store Javascript

Apple changed in iOS 9.2 on purpose to drive adoption of Universal Links. You'll need to implement those instead.

The best option is to use a service like (full disclosure: I'm on the Branch team) or Firebase Dynamic Links for this.

Related Topics

Leave a reply