Universal links in iOS

Last day I was asked to integrate deep linking in one of the app that I made last year. It was in objective-C. I had to face so many issues doing this as there are no proper documentation and the one that is available over the internet are not straight forward. Here, I will share what I understood and how I did it.

What Is A Deep Link?

What is Apple iOS Universal Links?

How Do Universal Links Work in iOS ?

How to Set Up Universal Links in iOS?

1. Configure your app to register approved domains

Image for post
Image for post
Image for post
Image for post
Image for post
Image for post

2. Configure your website to host the ‘apple-app-site-association’ file

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

Hosting the AASA File on Your Domain

Supporting Multiple Apps on the Same Domain

APPLE APP SITE ASSOCIATION (AASA) VALIDATOR

Preparing Your App to Handle Universal Links

func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
print("Continue User Activity called: ")
if userActivity.activityType == NSUserActivityTypeBrowsingWeb {
let url = userActivity.webpageURL!
print(url.absoluteString)
//handle url and open whatever page you want to open.
}
return true
}
Image for post
Image for post
Manipulating the components of the URL
//playground code..var str = “https://google.com/contents/someotherpath?category=series&contentid=1562167825"let url = URL(string: str)func queryParameters(from url: URL) -> [String: String] {let urlComponents = URLComponents(url: url, resolvingAgainstBaseURL: false)var queryParams = [String: String]()for queryItem: URLQueryItem in (urlComponents?.queryItems)! {if queryItem.value == nil {continue}queryParams[queryItem.name] = queryItem.value}return queryParams}
// print the url parameters dictionary
print(queryParameters(from: url!))
[“category”: “series”, “contentid”: “1562167825”]
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {
var isUniversalLinkClick: Bool = false
if launchOptions[UIApplicationLaunchOptionsUserActivityDictionaryKey] {
let activityDictionary = launchOptions[UIApplicationLaunchOptionsUserActivityDictionaryKey] as? [AnyHashable: Any] ?? [AnyHashable: Any]()
let activity = activityDictionary[“UIApplicationLaunchOptionsUserActivityKey”] as? NSUserActivity ?? NSUserActivity()
if activity != nil {
isUniversalLinkClick = true
}
}
if isUniversalLinkClick {
// app opened via clicking a universal link.
} else {
// set the initial viewcontroller
}
return true
}

Keep in mind:

Testing:

Issues:

If you enjoyed reading this post, please share and give some clapps so others can find it 👏👏👏👏👏 !!!!

iOS and tvOS developer, dreamer, photographer 🤨

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store