Redirects to app store if app is not installed
Asked Answered
M

1

19

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

Mattress answered 24/1, 2019 at 12:29 Comment(2)
Have a look here : #14048659Abiotic
I saw this. Looking a better solution as that is asked 6 years ago.Mattress
K
24

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://itunes.apple.com/us/app/google-maps-transit-food/id585027354?mt=8";
}

// 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

Krill answered 24/1, 2019 at 18:3 Comment(2)
Thanks, looks great! One more question, if a link has some data, e.g. a referral code - mysite/ref/5435287 - then how to pass back this code to app after it's installed from App Store? I see apps do it somehowQuadrate
Hey there, you need to check UIApplicationDelegate's docs to know how to initialize your app from a deep link (including accessing its URL parameters). developer.apple.com/documentation/uikit/…Hassi

© 2022 - 2024 — McMap. All rights reserved.