Skip to content
Roger Hu edited this page Jun 27, 2018 · 12 revisions

Overview

In the past, most iOS apps used custom URL scheme (i.e fb://auth). The problem is that two apps can claim the same URL scheme and there is no way to protect against which app should launch. Second, if the app was not installed, the URL doesn't open and there needs to be custom code to handle it. Universal links try to solve both of these problems, first by requiring verifiable ownership and also provide graceful fallback.

Setup

First, register your app at developer.apple.com and make sure the Associated Domains is enabled for the app.

Inside your XCode project, add the associated link in the format applinks:my.example.com:

The final step requires hosting an apple-app-site-association file where the appID corresponds to your app’s Team ID (visit https://developer.apple.com/account/#/membership/ to get the teamID) and the Bundle Identifier. In the example above, 9JA89QQLNQ is the Team ID and com.apple.wwdc is the Bundle ID.

{
    "applinks": {
        "apps": [],
        "details": {
            "9JA89QQLNQ.com.apple.wwdc": {
                "paths": [
                    "/wwdc/news/",
                    "/videos/wwdc/2015/*"
                ]
            }
        }
    }
}

Wildcard Links

To use wildcard app links, you must make sure that the subdomain and sub subdomains can serve the apple-app-site-association file. For instance:

  • app.domain.com (must serve the apple-app-site-association file)
  • server1.app.domain.com (must serve the apple-app-site-association)
  • server2.app.domain.com (must serve the apple-app-site-association)

Troubleshooting

Use the Console app, click on the Devices, and look for applinks in the system messages.

Testing on Simulator

Click on the Home button and make sure the app is currently not in the foreground. To launch the simulator, you can type this command at the Terminal prompt:

xcrun simctl openurl booted “https://www.example.com/content?id=2”

References

Clone this wiki locally