Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect to application if installed, otherwise to App Store

I know it's possible to link directly to an app in iOS by registering a custom scheme (e.g. so://) and it's also possible to link to the app in the appstore via itunes.

In many cases, the ideal flow is to provide a link that redirects to the app if it's installed and to the store if not. Is this possible, and if so, how?

Added for clarity, the scenario is I'm opening a link (http) from an e-mail on my iphone that's inviting me to join a group in an application. If the user has the app installed on that device it should open, otherwise the http link should redirect to itunes.

like image 736
ConfusedNoob Avatar asked Dec 27 '12 00:12

ConfusedNoob


People also ask

How do I stop getting redirected to the App Store?

Go to Site Settings and find Pop-ups and redirects; Make sure that the toggle next to “Block sites from showing pop-ups and redirects (recommended)” is greyed out. If it is blue and says Allowed, make sure to switch the toggle to OFF.


2 Answers

I think the more simple answer would be to set up a page on your server with the following javascript:

(function() {
  var app = {
    launchApp: function() {
      window.location.replace("myapp://");
      this.timer = setTimeout(this.openWebApp, 1000);
    },

    openWebApp: function() {
      window.location.replace("http://itunesstorelink/");
    }
  };

  app.launchApp();
})();

This basically attempts to redirect to your app and sets a timeout to redirect to the app store if it fails.

You could even make the code a little more smart, and check the user agent to see if they are an ios user, an android user, or a webuser, and then redirect them appropriately.

like image 162
BananaNeil Avatar answered Nov 08 '22 21:11

BananaNeil


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

like image 35
Lefteris Avatar answered Nov 08 '22 21:11

Lefteris