2

I've set up Universal Links on my iOS app using an aliased subdomain of my backend with a scheme like sudomain.mydomain.com. I want users that DON'T have the app installed to be redirected to our page in the App Store rather than hitting some nonexistent endpoint on our server (we don't have a webapp only a mobile backend).

I was thinking about doing something like this:

app.get('*', (request, response) => {

    const domain = request.headers.host,
      subdomain = domain.split('.');

    if ( subdomain[0] === 'subdomain'){
        response.redirect('www.linktoappstore.com');   
    } 
    ...
});

However I don't want this to interfere with Universal Linking for people who DO have the app installed. Are Universal Link get requests sent to my server or does iOS intercept them before that happens?

toddg
  • 2,863
  • 2
  • 18
  • 33

1 Answers1

5

This should work just fine.

When Universal Links are configured and your app is installed, the device does NOT hit the server before launching the app. This is because iOS caches the apple-app-site-association file when the app is initially installed, and if the URL being opened matches a path defined there, Universal Links kick in. In that situation, iOS completely bypasses any web request and immediately launches your app.

Of course, this means you can't track Universal Link traffic, which can become a major pain point. To work around this, you need something like Branch.io (full disclosure: I'm on the Branch team) to fill in the missing data.

Separately, if you're proxying the subdomain, make sure iOS doesn't see that as any sort of redirect. Otherwise the apple-app-site-association file won't be scraped at all (common Universal Link implementation issue).

Alex Bauer
  • 13,147
  • 1
  • 27
  • 44
  • 1
    Thanks! All seems to be working for me. I assume using a URL shortener will not work in this case (hence the need for Branch). – toddg Aug 17 '17 at 02:29
  • 2
    Correct, unless you somehow control the short URL domain and can add the AASA file there! – Alex Bauer Aug 17 '17 at 02:32
  • 1
    How does this work when using a wildcard in the applinks? How does it know which subdomain to use when looking for the AASA file? We've got this to work without wildcards, but can't seem to get it working with one. – dnc253 May 24 '18 at 15:32
  • 1
    With wildcards, iOS looks for the AASA file at the parent domain (or parent subdomain, in the case of a sub-subdomain). https://stackoverflow.com/a/40466044 – Alex Bauer May 24 '18 at 16:23
  • 1
    Yup, following the direction of that answer, things are now working for us. Thanks. – dnc253 May 24 '18 at 18:05