iOS Universal Links - any examples or help?

I need to use iOS universal links to allow the HTML5 version of our game to jump to a web page which allows players to download the app version, passing back some information about the player’s progress on the HTML5 version so they can continue where they left off.

Using extension-IAC I have this working fine now with Android, but am struggling with iOS.

I can make a web page trigger the starting of the app if it’s installed using a URI scheme (ie the web page opens a URI like com.my_company.my_app name ie my bundle ID). But, what I really want is the preferred method of using a universal link (eg www.mydomain.com/app) which should automatically open the app.

I’ve set up an apple-app-site-association file and have it hosted at my domain in the mydomain.com/.well-known folder (and being correctly served as a json file by my web server, validating correctly with validation tools etc). That looks like this…

{
    "applinks": {
      "apps": [],
      "details": [
        {
          "appID": "MYTEAMID.com.my_company.my_app name",
          "paths": ["/app/*"]
        }
      ]
    }
  }

My info.plist has these bits in it:

        <key>CFBundleURLTypes</key>
        <array>
            <dict>
                <key>CFBundleURLSchemes</key>
                <array>
                    <string>com.my_company.my_app name</string>
                </array>
            </dict>
        </array>

       <key>com.apple.developer.associated-domains</key>
        <array>
            <string>applinks:mydomain.com</string>
            <string>applinks:www.mydomain.com</string>
            <string>applinks:ios.mydomain.com</string>
        </array>

I’ve added the Associated Domains capability to the app’s provisioning files.

As far as I can tell, everything is set up such that now visiting mydomain.com/app should launch the app (if the app is installed on my phone), but it just gives me a 404 error. The only thing I’m not quite clear on is that the documentation I can find talks about using Xcode to include the Associated Domains entitlement. I assume I don’t do that because I’m using Defold, but I’m not sure what (if anything) I need to do instead of that. Is there another setting somewhere I need to make? Or is Xcode just setting up the info.plist file or capability which I’ve done already?

If anyone can advise on this, or point me at an example or documentation where someone has this working with Defold I’d be very grateful.

Thanks!

Managed to resolve this with a lot of trial and error.

Tips for anyone else who’s trying (can’t 100% guarantee this is ‘the answer’ but these are things I seemed to have to do before it would work which I only managed to work out by piecing together lots of different bits of documentation/posts from elsewhere, random guesses etc):

  • You need to include your applinks in an Entitlements.plist file which you can link to in the IOS section of game.project (I had them in info.plist, not sure if they need to be in both, but I have them in both and it now works)
  • You need to use a separate domain or subdomain for your applink - so, I have HTML5 game at www.mydomain.com which opens a page at www.mydomain.com/promo which then generates a link which takes you to ios.mydomain.com/app which gets picked up as a universal link
  • Not sure why but this validation tool - AASA Validator | Branch - didn’t recognise my appID as valid when I used “components” instead of “paths” in my aasa file
  • With your ios device in developer mode you can switch on Associated Domains Development and choose Diagnostics to check if your URL is correctly validating and will open an app on your device (was several hours in before I found out about this)
  • Your iOS device will only check the AASA file when the app is installed. I spent a lot of time changing things server side to see if it helped without realising that the app needed to be reinstalled to check on those changes.
  • This is probably the most useful bit of Apple documentation on the subject - TN3155: Debugging universal links | Apple Developer Documentation

Hope this helps someone else one day not spend the five hours I’ve just spent trying to get my head around this stuff :slight_smile:

1 Like

I spoke too soon. While I have been able now to get the app to open via the Universal Link, on iOS the IAC listener function does not trigger when it does so, so I can’t pass the payload the URL is passing to the game. If I use a URI scheme instead of a universal link, the IAC listener function does trigger on entry so maybe I can parse the incoming data.

So, my question - has anyone ever used the IAC library successfully on iOS using Universal Links (rather than a URI scheme)? Not sure whether it’s worth persisting with this or whether I should give up and just use a URI scheme (which I really don’t want to do).

I wonder if this shouldn’t be in a separate .xcent/.plist entitlements file referenced from game.project in the ios.custom_entitlements field? If you look at IOSBundler.java we treat the entitlements in a special way when code signing the app:

Thanks Bjorn, yes putting that into the separate entitlements file did help, the app does now open via the universal link.

However, going in that way the iac listener callback function doesn’t trigger, which it does when entering via the URI scheme (and also works fine when entering via an App Link on Android). My suspicion is there might be an issue with extension-iac… The example code also uses a URI scheme and not a Universal Link (and so the callback does trigger).

Have you seen any examples where the iac function does trigger on iOS when entering the app via a Universal Link? If so it must be something with my config but I can’t see that I’ve missed anything.

Thanks!

1 Like

Woo!

I know there are other games that are moving/have moved to Universal Links on iOS but I’m not sure how that is going and if they are making private modifications to extension-iac.

It shouldn’t be that hard to modify extension-iac to support Universal Links I think. Can you please open a feature request in the extension repo?

1 Like

Thanks Bjorn, have done so here - Make iOS version compatible with Universal Links · Issue #11 · defold/extension-iac · GitHub

1 Like