24

I have universal links working correctly, when the app is installed I see how the link opens the app, and when it's not installed opens the url in safari.

Actually what I would like to do is to redirect and go to the app store, so users can download the app directly. Im going to include a redirect on the html file, because I know universal links don't support redirects a the http server config level (anyway I think this is for the manifest file only, apple-apps-site-association)

Anyone can confirm if this is the right way to do it, or the only way to do it? I don't like the idea to open safari first, load my html (with the redirect only) and then go to the store. Looks like there's no easier way to do it.

User0123456789
  • 760
  • 2
  • 10
  • 25
Rodrigo.C
  • 1,123
  • 2
  • 10
  • 22

2 Answers2

30

You're right: server-side redirects aren't allowed for the apple-app-site-association file. However, I believe once the user opens a Universal Link and (assuming the app is not installed) lands on the URL, all options are on the table (server-side, or otherwise).

If the page on the other end of your Universal Links URL contains an instant JS redirection to your app's App Store page, that should work just fine. Something like this:

window.location = 'itms-apps://itunes.apple.com/us/app/imdb-movies-tv/id342792525'

But yes, no matter how you do it, Safari is still going to open. It'll flash past so quickly that the user likely won't even notice. Here's a real-time recording I just made of the Branch.io deep linking service's demo app doing exactly this process:

enter image description here

SudoPlz
  • 20,996
  • 12
  • 82
  • 123
Alex Bauer
  • 13,147
  • 1
  • 27
  • 44
  • 2
    Is there a specific reason for needing `setTimeout()` here? It doesn't seem like it would affect whether the redirection works. – kettlepot Apr 25 '17 at 13:00
  • You're right...not here. I was reusing part of another example and didn't simplify it enough – Alex Bauer Apr 26 '17 at 04:41
11

From here: https://developer.apple.com/library/archive/documentation/General/Conceptual/AppSearch/UniversalLinks.html

"When you support universal links, iOS 9 users can tap a link to your website and get seamlessly redirected to your installed app without going through Safari. If your app isn’t installed, tapping a link to your website opens your website in Safari."

You're not doing it wrong, that's just how they work.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Almo
  • 15,538
  • 13
  • 67
  • 95