iOS Universal URL

Munendra Pratap Singh
6 min readAug 25, 2023

--

In this article, we will try to understand what is Universal URL, How it works, and how we can use it in our application.

But But But, Before that let me brief you about the URL scheme and the challenges in the URL scheme.

In this article, we will cover the following topics

  1. URL scheme
  2. What is a Universal URL
  3. What Is An AASA (apple-app-site-association) File
  4. Configure the app for a Universal URL

URL scheme:

The URL scheme is an interesting feature provided by the iOS SDK that allows developers to launch system apps and third-party apps through URLs. For example, let’s say your app displays a phone number, and you want to make a call whenever a user taps that number. You can use a URL scheme(e.g. tel://743234028) to launch the built-in phone app and dial the number automatically. Similarly, you use the mailto scheme to open the Mail app (e.g. mailto:support@appcoda.com). Additionally, you can create a custom URL scheme for your own app so that other applications can launch your app via a URL

Custom URI schemes were the original form of deep linking for mobile apps. They are like creating a “private internet” for your app, with links that look like myapp://path/to/content. The advantage of custom URI schemes is they are easy to set up and most apps already have one.

The disadvantage of the URL scheme

  1. There is no way to check app is installed or not. if the user hits the URL scheme and the app is not installed on the device- nothing will happen.
  2. No unique app identification. There is no guarantee that a user will not install a third-party application that registers the same URL scheme

Now let's try to understand how universal URL can solve these problems

Universal URL

Apple introduced Universal Links in iOS 9 to solve the lack of graceful fallback functionality in custom URI scheme deep links. Universal Links are standard web links (http://mydomain.com) that point to both a web page and a piece of content inside an app. When a Universal Link is opened, iOS will check to see if the app is installed or not. If the app is installed on the device it will launch the app immediately without ever loading the web page, otherwise the web URL (which can be a simple redirect to the App Store) is loaded in Safari.

Before Universal Links, the primary mechanism to open up an app when it was installed was by trying to redirect to an app’s URI scheme in Safari. This put the routing logic in Safari, but there was no way to check if the app was installed or not. This meant that developers would try to call the URI scheme 100% of the time, on the off chance that the app was installed, then fall back gracefully to the App Store when not by using a timer.

Universal Links were intended to fix this. Instead of opening up Safari first when a link is clicked, iOS will check if a Universal Link has been registered for the domain associated with the link, then check if the corresponding app is installed. If the app is currently installed, it will be opened. If it’s not, Safari will open and the http(s):// the link will load.

What Is An AASA (apple-app-site-association) File?

Apple App Site Association (AASA) is a JSON file that enables iOS apps to securely communicate with their associated websites and safely prove domain ownership. AASA allows apps and their websites to share features, web credentials, and Universal Links to create a consistent user experience.

“The AASA file is downloaded onto a device during app install or update. This makes changing the file difficult since it will not be updated on every device until those devices update or reinstall.”

When a user on an iOS device running iOS 9 or later clicks on a link, the device checks whether that link should be handled by an app instead of being passed to Safari. These links can open the app if it is installed, or fall to the web

Here is the format of the Apple App Site Association

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


"appclips": {
"apps": ["ABCED12345.com.example.MyApp.Clip"]
}
}

Adding support for universal links is easy. There are three steps you need to take:

  • Create an apple-app-site-association file that contains JSON data about the URLs that your app can handle.
  • Upload the apple-app-site-association file to your HTTPS web server. You can place the file at the root of your server or in the .well-known subdirectory.
  • Prepare your app to handle universal links.

The file’s URL should match the following format:

https://<fully qualified domain>/.well-known/apple-app-site-association

You can test universal links on a device

Configure the app for a Universal URL

bellow are the steps to configure your app for a universal URL:

1. Register your app with Apple at developer.apple.com

  • Log in to developer.apple.com.
  • Click on Certificates, Identifiers & Profiles. Then, on Identifiers.
  • If you have an App Identifier, follow to the next section. If not, click on the + sign and fill out the form.

2. Allow Associated Domains on the app identifier.

3. Allow associated domains on your Xcode project.

  • Make sure your Xcode project has the same Team selected as your App Identifier.
  • Go to the Capabilities tab and choose your project file
  • Enable Associated Domains. Check your Bundle Identifier for your project matches the one registered with your App Identifier.

4. Add the right domain entitlement. Ensure the entitlement file is included at the build

  • Prefix applinks: to your domain tag.

That's not, now your app is ready to receive data from HTTP URLs

This article is more focused on Universal URLs. Here I will give you the basic differences between Universal Link and deep link.

Universal Link vs deep link

--

--

No responses yet