With the launch of iOS 9.2 Apple developers introduced to the public a new technology of apps opening - Universal links, in exchange for a deprecated URL scheme. The main advantage of a new development is identification of a unique application and a correct processing of the situation when it is not installed.

URL scheme

Before iOS 9.2 URL scheme was used for applications opening:

1. A special prefix was registered in the application, and your app was a handler for links with the given prefix.

Setting URL scheme prefix

2. Handler-method was implemented in AppDelegate:

func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {
    // Handler code here

When the link like urlPrefix://someUrlwithParamsOrWithoutThem is placed at an external source (at the site or when called from another application) the redirect to your application in openURL method took place, where data was taken from a received link and was processed correspondingly.

Disadvantages of this approach:

1. When the application the given link was addressed to is not installed - nothing happens. There is no possible way to check whether the application is installed or not (actual for web-pages. For mobile applications canOpenURL function is available). For such a case there were pages from which redirect was made first under the URL scheme and, after a while, to the application in AppStore.

2. No unique app identification. There is no guarantee that a user will not install a third-party application which register the same URL scheme, which will prevent the application from a unique identification.

Universal links

Apple engineers chose another way for projecting a new technology. Now it is a server from which the call is made, not an application that notifies the operating system that it is to process specific links. The operation system is addressed and unique identificators define whether the application is installed or not. If not, a certain algorithm is used by default. Also, the list of domains from which the start is allowed is created in the application, which makes it impossible for malefactors from not authorized sources to somehow affect the work of an application.

Stages of Universal links connection:

1. Turn on Associated Domains in Apple Member Center for your AppleID:

Associated Domain в Apple Member Center

and in project’s settings:

Associated Domain in the project settings

In Domains specify the domains transition from which should be processed by our application in applinks:domainName format.

2. Create JSON file called apple-app-site-association with the following content:

    "applinks": {
        "apps": [],
        "details": [
                "appID": "TeamId.AppBundleId_1",
                "paths": ["/pageURL/1", “pageURL/2”, “pageURL/3”]
                "appID": "TeamId.AppBundle_2",
                "paths": ["/pageURL/new"]
                "appID": "TeamId.AppBundle_3",
                "paths": [ "*" ]

NB! The file must have no extension and its size must not exceed 128 KB.

Apps field remains empty. Details field must contain the array of dictionaries, each of them describing by which application should every page be opened with.

AppID field consists of two parts divided by a dot. Your Team ID:

Team Id profile

and your application Bundle ID:

Bundle Id in the project settings

Example: XXXXXXXXXX.com.bundle.id

Paths field contains the array of strings - pages’ addresses, which must be redirected to your application (without domain name). Priority is determined by the references order. Thus, when you open page domain/pageURL/4 two first dictionaries from the example will be ignored and only the third one will fit the condition.

Symbols “*” can be used for conditions (any quantity of any symbols) and “?” (one symbol). Example: /pageURL/? - pages starting from /pageURL/0 to /pageURL/9 will be tested, but not /pageURL/10

**Also, you can specify exceptions in the format like [“xxx”, “NOT /pageURL/7”], and they must be specified before they are tested

***Paths array is case sensitive

Load a formed file to the root folder of the server

3. If your domain is signed by SSL certificate, this step can be omitted.

Otherwise, you should either sign your domain or put the certificate and the key in the same place where apple-app-site-association file is and sign your file by means of the following command:

cat apple-app-site-association-unsigned | openssl smime -sign -inkey yourdomain.com.key -signer     yourdomain.com.cert -certfile digicertintermediate.cert -noattr -nodetach -outform DER > apple-app-site-    association

4. Call processing

The processing is carried out in AppDelegate methods continueUserActivity and didFailToContinueUserActivityWithType.

You can get an original link by the following:

func application(application: UIApplication, continueUserActivity userActivity: NSUserActivity, restorationHandler: ([AnyObject]?) -> Void) -> Bool {
    self.parseURL(userActivity.webpageURL?.absoluteString) // original link as parameter for parsing function

In didFail method it is recommended either to open the transmitted link in Safari or display mistake to the user.

Examples of using:

  • The given technology can be used to create the page which will ignore the transmitted parameters and which will make redirect to AppStore if the application is not installed. If the application is installed the link will be intercepted and the application will open.

  • You can also share links of your products/page to user’s profile/news and if the application is installed this information will be displayed in the context of application. Otherwise, the link will open in Safari.

NB! Currently, the transition within a single domain is not intercepted by the operating system. It is recommended to place the page that is used only for the transition to the application at a third-party address.

Useful links

  1. Universal Links Support Documentation