iOS Deep linking: Universal Links
In this article we are going to explain only deep linking support for iOS application. We can also open iOS application with help of URL Scheme to check more about URL Scheme go through this article.
When you support universal links, iOS users can tap a link to your website and get seamlessly redirected to your installed app without going through Safari. If your app isn’t installed, tapping a link to your website opens your website in Safari.
In order to Support Deep Linking for iOS Application we have Three Steps.
1. Creating and Updating Association File
2. Associated Domains in Signing & Capabilities
3. Handle URL for Application
Creating and Updating Association File
To create a secure connection between your website and your app, you establish a trust relationship between them with help of apple-app-site-association
.
Add your apple-app-site-association
file in your website. You need to supply a separate apple-app-site-association
file for each domain with unique content that your app supports. For example, apple.com
and developer.apple.com
need separate apple-app-site-association
files, because these domains serve different content. In apple-app-site-association
you can define URL path need to be handled by app and not to be handled.
Note
Don’t append
.json
to theapple-app-site-association
filename.
Example of apple-app-site-association
file
{
"applinks": {
"details": [
{
"paths": [
"NOT /appbuilder/*",
"/maps/@*",
"/newsstand/sports?/*"
],
"appID": "RSBEB892Q3.com.dhana.dev.appbuilder"
},
{
"paths": [
"NOT /appbuilder/*",
"/maps/@*",
"/newsstand/sports?/*"
],
"appID": "T8SD4L2I17.com.dhana.appbuilder"
}
],
"apps": []
}
}
appID: Each app-specific dictionary contains an appID
key and a paths
key. The value of the appID
key is the team ID or app ID prefix, followed by the bundle ID.
paths: The value of the paths
key is an array of strings that specify the parts of your website that are supported by the app and the parts of your website that you don’t want to associate with the app.
details: In detail key we can have more than one dict i.e, in above example We have two applications named Appbuilder app in same device one is with debug profile [com.dhana.dev.appbuilder] and another with release profile [com.dhana.appbuilder]. If we have two app in one device on tap of link it will open first matching appID in the apple-app-site-association
i.e, in the above case it will open debug application.
apps: The apps
key in an apple-app-site-association
file must be present and its value must be an empty array for deep link.
There are various ways to specify website paths in the apple-app-site-association
file. For example, you can:
- Use
*
to specify your entire website - Include a URL path which should not support deep link, such as
NOT /appbuilder/*
, to specify a particular link - Append
*
to a specific URL, such as/newstands/sport?/*
, to specify a section of your website, you can also use?
to match any single character.
Updating to Associated domains
After you create the apple-app-site-association
file, upload it to the root of your HTTPS web server or to the .well-known
subdirectory. The file needs to be accessible via HTTPS—without any redirects—at https://<domain>/apple-app-site-association
or https://<domain>/.well-known/apple-app-site-association
.
Associated Domains in Signing & Capabilities
To set up the entitlement in your app, open the target’s Signing & Capabilities tab in Xcode and add the Associated Domains capability. If they’re not already present, this step adds the Associated Domains Entitlement
to your app and the associated domains feature to your app ID.
To add your domain to the entitlement, click Add (+) at the bottom of the Domains table to add a placeholder domain. Replace the placeholder with the appropriate prefix for the service your app will support and your site’s domain. Make sure to only include the desired subdomain and the top-level domain. Don’t include path and query components or a trailing slash (/)
.
Handle URL for Application
But now, say we want to redirect the user to the desired screen based on the URL parameters. We then have to implement the following method in the AppDelegate and SceneDelegate.
Closure
Taking all this into account, deep linking is crucial feature in today’s app, especially if you handling more URLs for the application to Users. Users consuming the data faster every day so our support to deep linking and navigating to the respective screens should be accurate.
You can refer anyone apple-app-site-association
file. I have added FAANG association files.
Facebook Apple Amazon Netflix Google