Everything you need to know about implementing iOS and Android Mobile Deep Linking

Real-world implementation in as few words as possible

Adam Geitgey
May 29, 2016 · 12 min read

What is Mobile App Deep Linking?

Normally when a user clicks a link to a website, the website opens in a web browser. Mobile App Deep Linking allows a corresponding native iOS/Android native app to open instead of a web browser:

Image for post
Image for post

Why would you want to implement Deep Links for your website?

There are some good arguments for pushing users into your native app instead of towards your website:

Image for post
Image for post
Google shows their own restaurant guide before any organic search results.
  1. Native app users are possibly more loyal and possibly spend more money than your website users (you need to measure this yourself)
  2. You might be worried about competition from Google!

Why might you not want to use Deep Links?

If your native app isn’t top notch, don’t force your users into using it. Only force users into your app if you really believe it’s a better user experience than your website. Otherwise you will frustrate your users.

Implementing Deep Links

Both iOS (9.0 and newer) and Android (all versions) provide good APIs for deep linking. You can implement deep linking on both platforms at the same time and a lot of the work overlaps.

Step 1: Mapping website URLs to screens in your app

First, you need to decide which urls on your website should link to which screens in your mobile app.

Image for post
Image for post

Step 2: iOS and Universal Links

Apple introduced a new deep linking API in iOS 9.0 called “Universal Links”. It provides a better user experience than the hacky deep linking options that existed in iOS 8.0 and below.

Implementing iOS Universal Links

In Step 1, we decided that links to https://www.example.com/products/* should launch our iOS app and show the correct product screen. This requires changes on both our website and in our native app.

  • The file must be served over https:// with a valid SSL certificate.
  • The file has to be located on your website at exactly /.well-known/apple-app-site-association. You can leave off “/.well-known/” and iOS will still find the file at the root of your website. But iOS always checks /.well-known/ first, so you’ll get lots of junk traffic if do that.
  • Because this file is only fetched once when the user first installs or upgrades the app, this file must be live on your website before your app is released. This also means that you can’t add new deep linking url patterns to your app until you push out a new app update to force users to refresh the file.
  • Check the Apple Docs for more options, like matching url patterns with wildcards.
  • Adopting the UIApplicationDelegate method application:continueUserActivity:restorationHandler: which is called when a user clicks on a deep link. You will be passed a NSUserActivity object with the webpageURL the user was trying to access. You can use that to figure out the correct screen to pop up in your app. It’s completely up to you to slice up the url, figure out what the user intended to see based on the url, and show the right screen in your app.

Step 3: Android and App Links

Android has supported deep links via Intent Filters for many years. But in Android Marshmallow (6.0), they expanded deep linking with App Links to give you more control over the user experience.

Implementing Android Intent Filters

In Android, Intent Filters let your app declare all the ways it can be launched by other apps. By adding a BROWSABLE intent filter, you are saying that your app can be started by a user clicking on a website url.

The Problem with Intent Filters

There’s one big problem with Intent Filters — any app can register them! You don’t have to prove you own a website to capture clicks on that website. This means your competition’s app can capture deep links from your website instead of your app!

Image for post
Image for post
Seven apps on my phone are trying to claim they own links to “reddit.com”!

Implementing Android App Links with Verification

First, update your AndroidManifest.xml file again to request that Android verify that you own your website:

  • You can generate the “sha256_cert_fingerprints” value with this command:
$ keytool -list -v -keystore my-release-key.keystore
  • Asset Link Verification only owns for Android 6.0 and above. Unfortunately that currently only represents 7.5% of users. The rest of your users will see the old Intent Filter behavior.

Promoting your app to website visitors

Now you have deep links implemented and it is working great for all of your existing users!

iOS Smart Banners

On iOS, you can choose to show users a Smart Banner like this:

Image for post
Image for post
  • The app-argument is passed to your app to tell it which screen to show when the app opens.

Android App Install Banners

Google also has their own version of a smart banner. They call it an App Install Banner. It pops up inside the user’s web browser when they visit your page:

Image for post
Image for post
  • The banner only shows up in Chrome, so the user won’t see a banner if they are using a third-party web browser.
  • The file must be served over https:// with a valid SSL certificate.
  • You must have a 144x144 png icon with a mime type of “image/png” or it won’t display a banner.

Common Problems

So you’ve implemented deep links and smart banners. Everything is working perfectly, right?

Universal Links used to work on iOS, but stopped working!

Apple made a really strange UI decision when they implemented Universal Links. When you click on a Universal Link, you’ll see the app open like this:

Image for post
Image for post

Universal Links don’t work for users on iOS using the Google Gmail or Inbox email apps

Yep, Universal Links won’t trigger for users clicking on email links in the Gmail or Inbox apps. It sucks. Google seems to care more about keeping users in their apps than providing a consistent iOS user experience.

Universal Links don’t work when clicking on links in the Facebook (or Twitter) iOS apps

Yep, Universal Links won’t trigger in the Facebook iOS app just like with Gmail. Again, Facebook seems to care more about keeping you inside their app (using a webview widget) than providing a consistent UX.

Universal Links don’t trigger if the user is already viewing my website

If a user is already viewing your website in Safari, clicking a link to a different page on that same site won’t make your app launch. This is by design on iOS (note that Android has the opposite behavior).

Takeaway Lessons

  • Deep linking can be a great feature to enable if your native app is top notch.
  • Don’t enable deep linking if your native app is terrible.
  • Deep linking pretty much always works as expected on Android, but the website owner has less control over the experience than the user.
  • Deep linking works well on iOS and the website owner has more control, but there are several cases where it doesn’t work at all (Like links inside the Gmail, Inbox and Facebook apps)
  • Don’t be hostile to your website users and force them to get your app to use basic features of your website. In other words, don’t do this:
Image for post
Image for post
Ugh. No thanks.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

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