Redirects to app store if app is not installed

Ramcharan Reddy picture Ramcharan Reddy · Jan 24, 2019 · Viewed 11.8k times · Source

Scenario is user will get a link to his email. If user clicks on the link, If app is already installed, app should open and if app is not installed it should redirect to app store.

I've seen deeplinks implementation, but I believe it needs some more implementation in backend too. Can any one help on this?

Redirect to application if installed, otherwise to App Store

gone through this. Is there any better way?

added gif for one more scenario:

in the below gif, from email to app it navigates directly? how?

enter image description here

Answer

Murilo Paixão picture Murilo Paixão · Jan 24, 2019

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 that the domain you're trying to respond is really yours.

With this, when your app is installed, it can respond to links of your own domain.

Now, if there's no installed app that's able to respond to a specific https domain, the system will simply open it on the browser. Thus, there's no way you can force AppStore to open links of your domain. So, what you can do is, when your web page opens on Safari, check if the running device is iOS and ask the system to open your app's page on AppStore app. But, you still have to pass through Safari.

Anyway, to request iOS to open the AppStore on your web page you can use itms-apps, like this:

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

if (iOS) {
  // Just use the link of your app on the AppStore and replace https:// with itms://
  window.location.href = "itms://itunes.apple.com/us/app/google-maps-transit-food/id585027354?mt=8";
}

// Here I'm redirecting to Google Maps on AppStore app.

Note: This is just a very simple example just to demonstrate the concept, it doesn't even check if the browser is really Safari. For this you can use a lib like mobile-detect.js