iOS Universal Linking Done Right

Michael H
4 min readJun 18, 2020

App development in 2020 is all about making life easy for the user. Yes, I know that’s always been the goal, but nowadays users want things as streamlined as possible. If your app is clunky, then you’re in store for either uninstalls or bad reviews.

There are many things to account for when trying to make a seamless experience. So many it would be futile to try and cover them in one post. So instead let’s focus on one thing that will both wow your users and leave them wishing all iOS apps behaved that way: Universal Links.

What’s a Universal Link?

A Universal Link is Apple’s way to let you take users directly into your app when they click a link. If a user is trying to perform an action such as resetting their password, they would much rather take the short route. Why bother going through the ordeal of getting an email, going from that email into a web browser, resetting their password, going to the app, and then signing back into the app with the new password. That’s way more work than necessary.

Instead we would like to send a user an email, have that take them directly into the app, and then handle it accordingly so when they change their password it will automatically log them in. Boom. Our 5 step process was just cut to 3.

When a user taps a universal link, a round trip call is made to Apple and the operating system immediately opens the proper app. It never opens the web browser, thus making opening your app a one step process. Even without getting into the details, the bottom line is it’s efficient and will wow users.

Setting It Up:

There are two key steps to setting up Universal Links:

  1. Set up your app
  2. Set up your server-side configuration

For the first of these you’ll need to have an app registered at developer.apple.com before proceeding. And once you have that taken care of, you’ll need to enable ‘Associated Domains’ on the app identifier. You can do this by going to developer.apple.com and then opening your app’s signing certificate under the ‘Certificates, Identifiers & Profiles’ section.

Then in your Xcode project under ‘Signing & Capabilities’ you’ll add a new domain to the ‘Associated Domains’ section. This is composed of “applinks:” as well as the hostname that your universal links will be composed of. For example applinks:www.examplesite.com.

(As a quick side note, if you are planning on connecting to more than one website with the same app then you will need an associated domain for each as well as an apple-app-site-association page for each. More one the second part in a bit)

That’s it for the capabilities set up in the app, but you’ll also need logic for what to do when a link launches your app. For this we can add the

func application(_ application: UIApplication, continue userActiviy: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
guard let universalLink = userActivity.webpageURL else { return false }
//Do something with the universal link info
return true
}

And now our app setup is complete. On to step 2: the server. The goal of this post is to focus on the app journey, but in order to do this you’ll also need the capability to set up a file at https://www.examplesite.com/.well-known/apple-app-site-associaton. The site name is obviously an example, but the path either has to match /.well-known/apple-app-site-association or /apple-app-site-association exactly. This is the page that contains JSON info about what links can take users straight into the app. Here’s a real world example of what this looks like for Facebook. And here’s a bare bones example of what the page should look like:

{
"applinks": {
"apps": [],
"details": [
{
"appID": “GJDKFJBIE.com.exampleapp.package",
"paths": [
"*"
]
}
]
}
}

It’s mostly cookie cutter JSON apple is looking for, but the important parts are the appID and paths values you set. The appID is a combination of your team ID (found in the Membership section on the developer portal) and the app’s bundle identifier. As for the paths array you can have as many values as you want. These determine which url paths will work successfully for the universal link redirect. * can be used as the catch all character, but you can further specify select url paths that you either want to include or exclude.

With both the server and the app setup in place, you should now be able to use an Universal Link successfully. To easily test you can open the Notes app, type your url that should link into the app, and then try tapping it!

Digging Deeper:

If things didn’t work as expected, it’s very possible it’s because of the version of iOS you are testing on. Universal Links changed with iOS 13, and to account for both older versions of the OS and iOS 13, you’ll need to update the apple-app-site-association file. Here’s a modified example from our previous one with a few sample urls too:

{
"applinks": {
"details": [
{
"appIDs": [
“GJDKFJBIE.com.exampleapp.package"
],
"components": [
{"/": "/mysamplepath/*"},
{"/": "/anothersamplepath/*"}
]
},
{
"appID": "GJDKFJBIE.com.exampleapp.package",
"paths": [
"/mysamplepath/*",
"/anothersamplepath/*"
]
}
]
},
"webcredentials": {
"apps": [
"GJDKFJBIE.com.exampleapp.package"
]
}
}

This modified version will account for both pre and post iOS 13 phones, so update your page accordingly and then try again.

Conclusion:

App development is increasingly becoming focused on the small things. What slight changes can be made to both surprise and please the end user. Universal Links offer a great opportunity for developers to leverage a powerful feature and reduce the number of steps users need to take to accomplish tasks.

If you found this post helpful and want to read more, please give it a clap or check out my other posts at FreeMobileTutorials.com!

--

--

Michael H

I’m a self taught Android, iOS and VR developer fascinated with the world of mobile. I’m passionate about learning new technologies by way of teaching others.