December 20, 2016

iOS Deep Linking - Common Challenges and Their Best Attempt to Solve Them


Introduction

"Deep links" are a powerful mechanism for making web/mobile app content more easily accessible. By automatically navigating to the desired page/screen we are able to improve the user experience dramatically.
Instead of requiring users to click through several pages – starting from the "home screen" – we can point them to a specific location within our app. Usually, a deep link is contained in, for example a push notification, an email, a Facebook advertisement, and so on. Furthermore, we can drive users back to our app from the mobile website with Smart App Banners in the Safari browser. See below for two real world examples. In the next few sections, we will show you what to consider when implementing such functionality on iOS.



Basic Implementation

To support deep links in iOS, the best approach is to make use of universal links. A universal link is a unique link that works for both your (mobile) website and your iOS app.1 Hence, to make use of universal links, we have to implement support for it on both sides.
Let's say we want to add support for a deep link to our ad insertion page, as pictured below. On the left, we see the page as it looks in our app, and on the right the corresponding mobile site.


The mobile link is https://mobile.willhaben.at/anzeigenaufgabe and we define this as our universal link. To make that deep link work for the willhaben app, we first have to associate our domains with the app in Xcode.


Second, for all those associated domains, we have to provide a server-side json file, which could look like the following:
{
  "applinks": {
    "apps": [],
    "details": [
      {
        "appID": "ABCD1234.at.willhaben.mobileapp",
        "paths": [
          "/anzeigenaufgabe"
        ]
      }
    ]
  }
}
This so-called apple-app-site-association file provides Apple with details about which apps we want to associate with which paths as universal links. It's important to note that this file can't be placed just anywhere. Since the specified paths must be relative, they need a base domain, and this is exactly where you have to put the association file. The table below illustrates this for our example.
URL Purpose
https://mobile.willhaben.at/apple-app-site-association Association File
https://mobile.willhaben.at/anzeigenaufgabe Deep Link
When a user taps on a push notification or on a link in an email, iOS sends the link to our app. To know what to do with it, our app has to handle the deep link explicitly. We won't go into detail on how this is done now, since it's beyond the scope of this text2, but basically the app has to parse the deep link and, depending on the path, decide which page should be opened. Usually, the deep link provides all of the information necessary to open the desired page.3
So far, so good. If we want to add support for more deep links, we basically just need to add them to the paths array. In the next sections, we will see why it's not always so easy to add support for a deep link in general, and why it requires more effort than "just" adding another entry to paths.

Challenges


In the previous section, we mentioned that the easiest way to add support for deep links is to use universal links. One best-practice for defining your universal links is to use SEO links. Unfortunately, in practice, you may not always have a SEO link handy for all the kinds of pages you may want to deep link to. In general, we have found that the more dynamic4 your website gets, the harder it is to find a generic pattern that will uniquely identify a page – which is the requirement for a deep link.
To get around the problem of not having a SEO link for every desired page, we added a "wildcard path", such as /dl/*, to our association file.
"paths": [
    "/dl/*",
    "/anzeigenaufgabe"
]
This allows us to use links in the form of https://mobile.willhaben.at/dl/my-non-seo-link-page as deep links. While this seems pretty obvious at first sight, it opens up yet another problem. Since we most probably want to use the deep link to link people into our app,5 the link itself must also work6 when, for example it is opened in an email on an iOS device that does not have our app installed, or even on any other mobile device or computer where it's not possible to run on the app.
For cases like this, we have to redirect the user to the dedicated page on our current platform, e.g. a mobile or desktop web browser. Our best advice is to try to find a generic pattern for defining those redirects. If you can't redirect to a corresponding site on your current platform – perhaps because that page only exists in the app – then you at least have to provide the user with a dedicated landing page or something similar. This should give the user an idea of how she can access the content of interest, so be aware of that.


Challenge

Think about the following scenario. You have released your app with support for a certain deep link, and in the upcoming version you want to add support for another one.7 Or, generally speaking, you want to add a new feature.
In modern software development, adding new features usually has a dedicated workflow, and here at willhaben this is no exception. In general, we could say every feature goes from development (dev) via testing to production (prod). To meet those requirements, our developers use a dedicated dev API-environment/app setup, and the same goes for our quality assurance team (QA) for testing. So, usually when we develop features, we don't use "production URLs", that is to say, any non-production URL would have a dedicated prefix or something similar that depends on the environment itself. See the table below for a possible setup.
URL Environment
https://mobile-dev.willhaben.at/anzeigenaufgabe development
https://mobile-uat.willhaben.at/anzeigenaufgabe user acceptance test (QA)
https://mobile.willhaben.at/anzeigenaufgabe production
Now we want to add support for the following deep link to our car ad insertion page. https://mobile.willhaben.at/auto-verkaufen
As mentioned above, every supported deep link must be part of the paths array - relative to the server where our association file lies. Now you can immediately see the problem. We can't define our dev deep link, since our app is configured to point to the association file on the prod server.

Solution

One obvious answer would be simply to add an association file to our dev server and configure our app accordingly, by adding that associated (sub)domain, see above. Then, we could use our dev links within our dev app like we usually do when we develop other features. The same is true for QA and the testing environment. Finally, we'd ship the new version of the app to our users. There are several reasons why this might not be the best idea in this case, which we will examine below.
For security reasons, among others, our dev and QA environments are not exposed to the public. Howerver, Apple needs to crawl the content of the association file on our server to associate our app with our domain. Since making parts of those environments publicly accessible is not really an option,8 we need to find a different solution. Additionally, and in my opinion the deciding argument, from a practice perspective, it makes life a lot easier if you setup your dev/testing chain for deep linking as close to production as possible.9
Remember, we have to handle a deep link once its handed over to our app. This means we have to parse the URL and decide, upon the result, which page to open. Since this is a crucial function of our app, we advice to add unit tests for at least the URL parsing. Now, just imagine the URLs differ depending on the setup.
Furthermore, our app has to decide if it supports a deep link and, if not, open the system browser as a fallback. While it doesn't require rocket science to solve this, and it could be done in a way that it is environment-dependent, we decided against it, to remove a layer of complexity in the whole deep/universal linking topic, since making it work in general is complex enough. To get our closest-to-production setup for development, we use our regular association file and modify the apps entries by adding the appID along with the paths, such as:
{
  "applinks": {
    "apps": [],
    "details": [
      {
        "appID": "ABCD1234.at.willhaben.mobileapp",
        "paths": [
          "/anzeigenaufgabe"
        ]
      },
      {
        "appID": "DCBA4321.at.willhaben.mobileapp.dev",
        "paths": [
          "/anzeigenaufgabe",
          "/auto-verkaufen"
        ]
      }
    ]
  }
}
Now, our dev app supports our new deep link https://mobile.willhaben.at/auto-verkaufen, and we can add all the code for handling it accordingly. We can send out emails, push notifications, and Facebook ads containing the link, and we can see if our app behaves correctly. Especially in the dev/test phase, where you usually work together with different people from different departments, it removes a source of error if there is one deep link for a page and not several.
From a technical perspective, this allows us to write expressive unit tests that don't have to fiddle around with details about environments.
let url : URL! = URL(string: "https://mobile.willhaben.at/auto-verkaufen")
let deepLinkPage = sut.parseUrl(url)
XCTAssert(deepLinkPage == .carAdInsertionProductSelection)
Another big advantage is that we can actually see if everything plays together as expected by trying out the Smart App Banner. Note that it suggests to open our dev app.
Tapping that link in the banner, or the one in the email, push notification, and so on, shows us if our link brings us to the desired page in the app. Once we confirm that it behaves as expected, all we need to do is to add the link to the paths for our production app and release it.

Summary


Confidence

Although universal/deep links sound straightforward in theory, a lot of technologies have to play together to make them work correctly, and it's easy to mess up. We pointed out what you should consider during development and testing to limit complexity. Furthermore, we have tried to remove some of the subtleties which might go wrong during implementation. This allows us to catch errors early and not only when we have already released the app.
Once we have added a new deep link successfully in development, we can feel pretty confident that we have done everything right to make it work in an upcoming app release without interfering with the currently released version of the app.

Risks

An attentive reader will have noticed that the presented setup also yields some risks and problems. Since we need to alter the association file on our production server, we might screw up things there. That's why you should only use this approach when you have a system where you can quickly update your association file without going through a complex server release scenario.10 Another downside is that, if your deep link contains environment-specific data, for example user data, it might be possible to yield an inconsistent state, depending on your handling of that data.

Advantages

The advantages of the production-near setup outweigh those risks though, and for us it's better to "break" our deep link support than having an app out there that behaves incorrectly. This is especially true because, on iOS, it usually takes at least a few days to release an app update to fix any problems.
With the presented best practices used at willhaben, we try to prevent the latter, and while there’s a lot more regarding this topic which one could talk about, we hope we have given you some inspiration when you're still struggling to figure out how to get it done.

  1. In the rest of the article, the terms deep link and universal link are sometimes used interchangeably.
  2. A great introductory article can be found in the Apple docs.
  3. Your deep link could contain query parameters, for example https://mobile.willhaben.at/my-deep-link?param1=x&param2=y. In the best case, you could directly query your API with this URL, without manipulating it or building a new one.
  4. We use the term dynamic in the sense of user-generated content, so your URL path and parameters might depend on that.
  5. Note that we could also use deep links within the app.
  6. In the sense of "try your best to deliver the expected content to the user".
  7. Apple states that the apple-app-site-association file is fetched upon app install, yet the documentation does not say how frequently an installed app re-downloads the file to update its associations.
  8. We could make our dev environments accessible to Apple by allowing certain IP ranges, but together with our operations team we decided against that, since we wouldn't know if we configured it correctly for all necessary IP ranges. Further it would probably require constant adaptions.
  9. That goes for any feature in general, but especially for this topic since different technologies have to play together.
  10. Be sure to validate your JSON and your universal links before deploying!

18 comments:

  1. As a writer of Dissertation Help UK I know Deep links are really amazing method for make app content more with no trouble and easy to get.

    ReplyDelete
  2. Knowing top web improvement aptitudes is vital in this day and age of changing and regularly propelling innovation. With website pages the main way individuals learn, mingle, work, and even date the interest of a page matters like never before some time recently. To remain in front of the group it is basic to know about these improvements.

    ReplyDelete
  3. Would you recommend any company to conduct a market research on how to improve IOS Deep Linking So where’s the shining light Truly an exciting time to be a part of OSI Research. Daniel Craig Coat

    ReplyDelete
  4. As a video editor in the filed of 2d and 3d animation at Corporate Animated Video Production Company - HelloAnimations, I would say that deep link challenges is a conceptual base topic and with this huge info I really understand what you are going to deliver. Great

    ReplyDelete
  5. it has been the useful database sql books information

    ReplyDelete
  6. what a deep information iOS Deep Linking, literally i don't know about this, because of this any navigate quick response user can navigate very quickly and i will implement my online Resident Evil Black Jacket Getmyleather website.

    ReplyDelete
  7. Your information is good and very helpful for me. Thanks for the post.!
    Aadhar Pay Apps

    ReplyDelete
  8. Deep linking has been redefined to mean using a mobile application URI to refer.we use mobile applications, connecting them all together.
    Law Essay Writing UK

    ReplyDelete
  9. Good Knowing top web improvement aptitudes is vital in this day and age of changing and regularly propelling innovation. Rock dss vest

    ReplyDelete
  10. Understanding the improvement capabilities of top-level websites is critical in this day and age changes and regularly advancing innovation www.dissertationplus.co.uk/write-my-dissertation. With the main page of the page, personal learning, contacts, work, and even date of interest, as never in the most recent period of the page.

    ReplyDelete
  11. Very deep information on iOS linking. The article is easy to follow through. I will share the article with my do my paper for me writers who will also learn something from it. Thanks for sharing.

    ReplyDelete
  12. We could make our dev surroundings open to Apple by permitting certain IP ranges, yet together with our operations group we ruled against that, since we wouldn't know whether we arranged Can You Write My Dissertation

    ReplyDelete
  13. Reall authentic information this is really helpful post, i am as a programmer i know one thing is really importent colonical url is really importent for a good urls because of this your website kepp good ranking on google search engine great, job keep it up!Jared Leto Joker Coat

    ReplyDelete
  14. Student loan defaults are rising in the United States; at the same time, someone says that the value of a college education has not only declined significantly, but this very value has also been destroyed by a methodical system of "financial rapine". Would you like to learn more? Read on..academic writing

    ReplyDelete
  15. Very Informative and useful for everyone.http://globalattestation.com/

    ReplyDelete
  16. Nice to be visiting your blog again, it has been months for me. Well this article that i've been waited for so long. I need this article to complete my assignment in the college, and it has same topic with your article. Thanks, great share.
    Read More Here

    ReplyDelete
  17. Reall authentic information this is really helpful post, i am as a programmer i know one thing is really importent colonical url is really importent for a good urls because of this your website kepp good ranking on google search engine great, job keep it up

    ReplyDelete