Article

Allowing Apps and Websites to Link to Your Content

Use universal links to link to content within your app and share data securely.

Overview

Universal links let you connect to content deep inside your app. Users open your app in a specified context, allowing them to accomplish their goals efficiently.

Universal links provide several key benefits. First, iOS redirects universal links directly to your app without routing through Safari or your website. In addition, one URL works for both your website and your app, and you can use standard URL processing for routing and payload extraction.

When users install your app, iOS checks a file stored on your web server to verify that your website allows your app to open URLs on its behalf. Only you have the ability to store this file on your server, securing the association of your website and your app.

Support Universal Links

Take the following steps to support universal links:

  1. Create a two-way association between your app and your website and specify the URLs that your app handles. See Enabling Universal Links.

  2. Update your app delegate to respond to the user activity object iOS provides when a universal link routes to your app. See Handling Universal Links.

Universal links allow users to open your app when they tap links to your website within Safari pages, within WKWebView and UIWebView views, and links that result in a call to open(_:options:completionHandler:), such as those that occur in Mail, Messages, and other apps.

When a user browses your website in Safari and taps a universal link in the same domain, iOS opens that link in Safari, respecting the user’s most likely intent to continue within the browser. If the user taps a universal link in a different domain, iOS opens the link in your app.

Communicate with Other Apps

UIKit apps can communicate through universal links. Supporting universal links allows other apps to send small amounts of data directly to your app without using a third-party server. 

Define the parameters that your app handles within the URL query string. For example, a photo library app might specify parameters that includes the name of an album and the index of a photo to display. Examples of URLs could include the following:

https://myphotoapp.example.com/albums?albumname=vacation&index=1
https://myphotoapp.example.com/albums?albumname=wedding&index=17

Other apps craft URLs based on your domain, path, and parameters, and ask your app to open them by calling the open(_:options:completionHandler:) method of UIApplication. The calling app can ask the system to inform them when your app opens the URL. For an example, see Listing 2.

Listing 2

An example of another app calling your universal link.

        if let url = URL(string: " https://myphotoapp.example.com/albums?albumname=vacation&index=1") {
            UIApplication.shared.open(url) { (result) in
                if result {
                    print("The URL was delivered successfully")
                } else {
                    print("The URL failed")
                }
            }
        } else {
            print("Bad URL")
        }

For more information on handling links within your app, see Handling Universal Links.

Topics

Universal Links

Enabling Universal Links

Add an entitlement to your app and a file to your website to enable universal links.

Handling Universal Links

Prepare your app to respond to an incoming universal link.

Custom URLs

Communicating with Other Apps Using Custom URLs

Receive data from other apps using specially formatted URLs.

See Also

Application

Managing Your App's Life Cycle

Understand how the app delegate manages your app's high-level behavior.

class UIApplication

The centralized point of control and coordination for apps running in iOS.

protocol UIApplicationDelegate

A set of methods that are called by the singleton UIApplication object in response to important events in the lifetime of your app.

func UIApplicationMain(Int32, UnsafeMutablePointer<UnsafeMutablePointer<Int8>?>, String?, String?) -> Int32

Creates the application object and the application delegate and sets up the event cycle.