E2EHIRING Logo
Jobs
Jobs
courses
Courses
mentorship
Mentorship
more
Moredropdown
E2EHIRING Logo
more
Jobs
Jobs
courses
Courses
mentorship
Mentorship
HomeSepratorIconBlogsSepratorIconHow to Set Up Universal Links in iOSSepratorIcon

How to Set Up Universal Links in iOS

Han SoloUday Kc
calendar6 Jul 2022
poster

What is Apple iOS Universal Links?

Apple introduced Universal Links in iOS 9 as a solution to 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 checks to see if any installed app is registered for that domain. If so, the app is launched immediately without ever loading the web page. If not, the web URL (which can be a simple redirect to the App Store) is loaded in Safari.

Universal Link Integration Guide

  1. Register your app at developer.apple.com
  2. Enable Associated Domains on your app identifier.  
  3. Enable Associated Domains on in your Xcode project. Add an item under domains, in the format applinks:yourwebsite.com where yourwebsite.com is your website domain.
  4. Configure your website to host the "apple-app-site-association" file                                                                                                                                                                                                           

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

The AASA (short for apple-app-site-association) is a file that lives on your website and associates your website domain with your native app. In other words, it’s a safe way to prove domain ownership to iOS. With URI schemes, which were the standard way for opening apps on iOS until iOS 9, app developers could register any URI scheme of their liking and iOS, without any verification, would respond to those URI schemes by opening apps. For example, if some developer registers the fb:// URI scheme for a test app, there was nothing to stop that, even thoughfb:// is used by the Facebook native app. The AASA file makes Universal Links unique and secure because there is no way for other developers to host an AASA file on the facebook.com domain.

Let’s look at some basics of the apple-app-site-association file that will help you in building and hosting one on your domain.

The AASA file contains a JSON object with a list of apps and the URL paths on the domain that should be included or excluded as Universal Links. Here is a sample AASA file:

{
  "applinks": {
    "apps": [],
    "details": [
    {
      "appID": "KFFNVC27GU.com.yourcompany.YourProject",
      "paths": ["*"]
    }
    ]
  }
}

The appID here consists of your team ID combined with the app’s bundle ID.

Team ID:

You’ll find this in your Apple developer account. Go to Apple developer center. Log into the web site, click on Membership, then look for Team ID in the Membership Information section.

Bundle ID:

You’ll find this under the General tab in your project settings in XCode.

Once this AASA file is created, just host it in the root folder of your domain.

Some points to keep in mind while hosting the AASA file:

  • It should be served over HTTPS
  • Be sure to define a ‘content-type’ header with application/json MIME type.
  • Don’t append .json to the apple-app-site-association filename.
  • Size of the file shouldn’t exceed 128 Kb.   

After hosting, you must be able to see the json text when you open the following URL in your browser.

https://yourwebsite.com/apple-app-site-association (Example:- https://facebook.com/apple-app-site-association)

You can validate this step using a tool by branch.io.

Goto the following link and enter your domain name. It will check if AASA file is valid and is accessible.

Link:-  https://branch.io/resources/aasa-validator/#resultsbox

 Handling links received in the app

 If everything went well, you will now receive universal links in your app, so let us see how to handle them.

    AppDelegate.swift

   In your AppDelegate, add the following delegate function; it is called upon receiving an app link.

    func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Boo

          guard userActivity.activityType == NSUserActivityTypeBrowsingWeb

           let url = userActivity.webpageURL, let components = URLComponents(url: url, resolvingAgainstBaseURL: true) else {

                    return false

                }

         debugPrint("URL==\(userActivity.webpageURL?.absoluteString)")

            return false

    }

Output

Reference:-  https://developer.apple.com/library/archive/documentation/General/Conceptual/AppSearch/UniversalLinks.html

That's all folks!


Recent Posts

Rapid Changes in the Coding World: Need for High Skilled Programmers e2eHiring Bridges this Gap with the Mentorship Program April 2023

Rapid Changes in the Coding World: Need for High Skilled Programmers e2eHiring Bridges this Gap with the Mentorship Program April 2023

How to publish your Android app on Google Play Store

How to publish your Android app on Google Play Store

Creating Dynamic User Interfaces with Android Motion Layout

Creating Dynamic User Interfaces with Android Motion Layout

Bean Life Cycle

Bean Life Cycle

Pom.XML

Pom.XML

copycopycopycopy

Han Solo

Recent Posts

Rapid Changes in the Coding World: Need for High Skilled Programmers e2eHiring Bridges this Gap with the Mentorship Program April 2023

Rapid Changes in the Coding World: Need for High Skilled Programmers e2eHiring Bridges this Gap with the Mentorship Program April 2023

How to publish your Android app on Google Play Store

How to publish your Android app on Google Play Store

Creating Dynamic User Interfaces with Android Motion Layout

Creating Dynamic User Interfaces with Android Motion Layout

Bean Life Cycle

Bean Life Cycle

Pom.XML

Pom.XML