Tomer Eden
Tomer Eden

Reputation: 101

IOS Universal links using expo is NOT working

I've an EXPO app and i'm trying to get into the app from external links (universal/deep linking), Android is up and running perfectly and IOS is not working. the app.json file is configured as described here:

"associatedDomains": [
        "applinks:*.<DOMAIN_NAME>.com",
        "applinks:<SUB_DOMAIN>.<DOMAIN_NAME>.com"
  ]

And because of my app is using WEBVIEW of my original website, the file /.well-known/apple-app-site-association is located at my client repository under the SRC folder like so:

    Content-Type: application/pkcs7-mime
    
    {
      "applinks": {
        "apps": [], 
        "details": [{
          "appID": "<APP_ID>",
          "paths": ["/login/*"]
        }]
      }
    }

Now, AASA validator is OK, but external links still not opening the native app!!! What to do?!

Upvotes: 10

Views: 4453

Answers (1)

codewizard
codewizard

Reputation: 1627

I found the answer on the expo forums and want to post the solution here because I spent hours/days trying to figure out the answer. And kept running into this question here on SO. And due to only being easily testable on production(vs local or release channel deployments). I want to save other users the pain of releasing their app with broken universal deep links.

Expo's documentation isn't clear here. In the iOS section of Expo's linking guide is fairly vague and some of the language is not explicit or clear enough. To make matters worse everything you find on SO or elsewhere is filled with conflicting and out of date info.

While the OP's question is likely solved solely by the last item in this list, I want to cover a couple of things I also had issues figuring this out for posterity and to clear things up I kept trying to piece together:

  1. appID is basically a combination of the iOS team ID which can be found in the apple developer console under membership. And the bundle id found in app store connect > app > app information (or it should also be in your app.json).
  2. Some of apple's documentation can be confusing and wildcards do match more than one character. So for example a path of "/auth/*" will properly route the a url with the path of "/auth/login".
  3. You do not need to sign your AASA file.
  4. Do not include https or paths in your associatedDomains configured in app.json it should just be the domain (e.g. "applinks:google.com").
  5. The working mime type for your AASA is application/pkcs7-mime and not application/json
  6. you're AASA file can me in your root directory or .well-known [docs], I suggest placing it on both as this will help create some redundancy. You can upload one file and configure your server to resolve the same file.
  7. You need to enable associated domains service for you identifier. Expo states this in their documentation but the navigation to where to do this is out of date. On the developer portal > Certificates, Identifiers & Profiles > identifiers > click on the identifier that maches your app's bundle ID > capabilities > Check "Associated Domains" It will tell you that this will invalidate your signing profile and you'll need a new one to deploy your app. So long as you are in a managed expo app, expo will handle this for you when you create a new build.
  8. The main problem you're facing is that the AASA file or apple-app-site-association has gone through 3 different iterations with different schemas. Each schema is fairly different and you need to combine all 3 schemas to support all current + older versions of iOS. The schema in the OPs question is used by ios 11 & 12 and not supported by iOS 13+ (which came out 2019). Expo's documentation is unclear about this and makes it sound like the displayed version will work with all versions and you can use the new schema if you want the added features, however the new schema is absolutely necessary to work with newer iphones. The expo documentation has the new schema minified so you don't even realize it exists if you're not paying attention.

Another user explained this solution in depth on the expo forums - I won't go into as much depth but will include his combinations of the different schemas that did work for me so that it's easier to find. (although the new schema is probably sufficient if you don't plan on supporting anything lower than iOS 13. as 15 is the current version as of this writing)

Example of all the schemas combined.

{
"applinks": {
    "apps": [],
    "details": [
        {
            "appIDs": [ "TEAMID.bundleidentifier", "ABCDE12345.com.example.app2" ],
            "components": [
                {
                    "#": "no_universal_links",
                    "exclude": true,
                    "comment": "Matches any URL whose fragment equals no_universal_links and instructs the system not to open it as a universal link"
                },
                {
                    "/": "/buy/*",
                    "comment": "Matches any URL whose path starts with /buy/"
                },
                {
                    "/": "/help/website/*",
                    "exclude": true,
                    "comment": "Matches any URL whose path starts with /help/website/ and instructs the system not to open it as a universal link"
                },
                {
                    "/": "/help/*",
                    "?": { "articleNumber": "????" },
                    "comment": "Matches any URL whose path starts with /help/ and which has a query item with name 'articleNumber' and a value of exactly 4 characters"
                }
            ]
        },
        {
            "appID": "TEAMID.bundleidentifier",
            "paths": [ "/buy/*", "/help/website/*",  "/help/*" ]
        },
        {
            "appID": "OTHTEAMID.otherbundleidentifier",
            "paths": [ "/blog", "/blog/post/*" ]
        },
        {
            "appID": "YAOTHTEAMID.yetanotherbundleidentifier",
            "paths": [ "*" ]
        }
    ]
},
"activitycontinuation": {
    "apps": [
        "TEAMID.bundleidentifier",
        "OTHTEAMID.otherbundleidentifier"
    ]
}

Example of the new schema if you don't need to support older versions of iOS

{
"applinks": {
    "apps": [],
    "details": [
        {
            "appIDs": ["ABCDE12345.com.example.app", "ABCDE12345.com.example.app2"],
            "components": [
                {
                    "#": "no_universal_links",
                    "exclude": true,
                    "comment": "Matches any URL whose fragment equals no_universal_links and instructs the system not to open it as a universal link"
                },
                {
                    "/": "/buy/*",
                    "comment": "Matches any URL whose path starts with /buy/"
                },
                {
                    "/": "/help/website/*",
                    "exclude": true,
                    "comment": "Matches any URL whose path starts with /help/website/ and instructs the system not to open it as a universal link"
                },
                {
                    "/": "/help/*",
                    "?": { "articleNumber": "????" },
                    "comment": "Matches any URL whose path starts with /help/ and which has a query item with name 'articleNumber' and a value of exactly 4 characters"
                }
            ]
        }
    ]
}

Upvotes: 29

Related Questions