iOS 9 Learning Series: Universal links to iOS 9 (Universal links)

Source: Internet
Author: User

Http://www.cocoachina.com/ios/20150911/13321.html

This article by Cocoachina Translator Amon Xu (blog) translated from Hoko's blog
Original: Breaking down IOS 9 Universal Links

On WWDC 2015, Apple announced a deep link feature for IOS 9, a so-called universal link, with the video address [seamlessly linked to your App]. While it is not a must-have feature, some attention needs to be drawn.

There are so many confusing and wrong information on the Internet that the WWDC itself does not describe the details. Fortunately, in Hoko we added this feature on our smart links, so we can seamlessly guide users to the APP.

What is a generic link?

It's clear that Apple is pushing APP developers to have a better experience on deep links. All the news revolves around deep link technology. At the same time, Apple has launched a generic link: a convenient way to launch apps via traditional HTTP links, using the same URLs to open websites and apps.

With a unique URL, you can link a specific view to your APP, without the need for a special schema. Imagine Twitter using a generic link, then you're on Twitter. COM click on a link, your IOS device will automatically open this page in Twitter, not when you do not have to go to the normal page. The user experience is smooth and, most importantly, the user will not lose context (skip to the APP and no longer leave an empty tag on Safari).

Ready to use generic links

Implementing generic links is not difficult, but first you must follow some prerequisites. As follows:

    • Have a registered domain name

    • Access domain names via SSL

    • Support for uploading a JSON file to your domain

    • At least IOS 9 Beta 2 version [download], this is important, because if it is the previous beta version you need to do extra work.

    • At least Xcode 7 Beta 2 [DOWNLOAD]

If you have one, follow the 3 steps below.

1. Add domain name to capabilities

First, you must add your APP domain name in Xcode's capabilities, you must use Applinks: Pre-set it: Also add some subdomains and extensions you might have (www.domain.com, news.domain.com, etc.).

Add all domain names with applinks: prefix and don't forget to include all possible subdomains *

This will enable your APP to request a special JSON file from your domain apple-app-site-association. When you start the APP for the first time, it will download the file from Https://domain.com/apple-app-site-association. Skip to the next step to learn how to build this file.

2. Uploading apple-app-site-association files

The file must exist and can be accessed using SSL for security reasons through a get request. You can open a text editor and write a simple JSON format like this:

12345678910 {  "applinks": {    "apps": [],    "details": {      "TBEJCS6FFP.com.domain.App": {        "paths":[ "*"]      }    }  }}

Set a list of allowed paths based on the Paths key (the path you want the app to respond to), or just an asterisk if you want to open the app regardless of the path.

You may want to know where TBEJCS6FFP.com.domain.App came from and basically, it is the bundle ID that joins your team's identity. You can get your team logo from your [Apple Development Account page]:

This page has your team logo and you can copy and paste it into the apple-app-site-association file.

Bundle IDs can be found in the project's target-general:

Check the General tab and copy and paste the bundle ID into the apple-app-site-association file

Finally, upload this file to your domain root directory. If you open https://domain.com/apple-app-site-association to see your files, then you can move on to the next step.

3. Working with generic links in the APP

In order to support universal links in the APP, you need to implement [Application (_:continueuseractivity:restorationhandler:)] in appdelegate. Although this approach can be used for many different purposes (such as [Handoff] and [search API]), we will only focus on how to handle the received generic links.

123456789101112131415161718192021222324252627282930313233343536 import UIKitextension AppDelegate {    func application(application: UIApplication, continueUserActivity userActivity: NSUserActivity, restorationHandler: ([AnyObject]?) -> Void) -> Bool {        ifuserActivity.activityType == NSUserActivityTypeBrowsingWeb {            let webpageURL = userActivity.webpageURL! // Always exists            if!handleUniversalLink(URL: webpageURL) {                UIApplication.sharedApplication().openURL(webpageURL)            }        }        returntrue    }        private func handleUniversalLink(URL url: NSURL) -> Bool {        iflet components = NSURLComponents(URL: url, resolvingAgainstBaseURL: true), let host = components.host, let pathComponents = components.path?.pathComponents {            switchhost {            case"domain.com":                ifpathComponents.count >= 4 {                    switch(pathComponents[0], pathComponents[1], pathComponents[2], pathComponents[3]) {                    case("/""path""to", let something):                        ifvalidateSomething(something) {                            presentSomethingViewController(something)                            returntrue                        }                    default:                        returnfalse                    }                }            default:                returnfalse            }                    }        returnfalse    }}

If the provided useractivity is a nsuseractivitytypebrowsingweb type, then it means that it has been proxied by the generic link API. In this case, it guarantees that the user opens a URL that will have a non-empty Webpageurl property. According to the previous example, this will be the embodiment of Http://domain.com/path/to/thezoo.

To make sure your APP can translate URLs into actual content, you need to do the following steps:

    • Use [nsurlcomponents] to simply parse Webpageurl to host, such as domain. COM), the path consists of the same (such as ["/"], "path", "to" and "Thezoo").

    • Ensure that host is recognized.

    • Try to match pathcomponents to the APP's known content.

    • Verify that the content can actually be rendered.

    • Renders the content to the user.

If any of these steps fail, Apple recommends that your APP open webpageurl on Safari to show the error.

Summarize

Overview of the workflow that is a generic link

Disadvantages of Universal Links

Generic links are a good idea for developers, but there are some drawbacks that can lead to unpopular.

Universal links are only available for IOS 9 +

Configuring APP support for universal links means that only users running IOS 9 can enjoy this technical advantage. Previous versions of users will not be able to open the APP when clicking on a link to the page. Instead, they will return to the browser and Web page, just like the previous normal web links.

Hoko then provides mobile deep links for IOS 5 and later users. As a result, your mobile deep links will be able to run on almost any iOS device, whether they are iOS 9 or not.

Universal links are always returned to the page you created earlier

If you want to return to the homepage or a website that is completely unrelated to the APP? Achieving this requires some extra work, and configuring a Web page can guide the user to your target page. In addition, if you do not have a website, it will be an impossible solution.

You can easily solve this problem by using Hoko smart links and their adaptive returns. For each smart link you create, you can choose what happens on each platform if you don't have the APP installed. In addition you can set back to your website, ITunes store page or other external website.

With generic links, developers must deploy a website to associate apps

This may be bad news for small developers, who may not be able to afford or maintain a website, but still want to access their APP via web links.

Hoko can solve this problem because it acts as a developer's website, each APP hosted in a different subdomain. As a result, developers simply create smart links, publish their URLs, and then seamlessly open the APP every time.

The link between the APP and the website is done by the profile created and hosted on the developer's website.

With Hoko, you can skip these complex configurations as we make it available out of the box. In addition, our servers are run with industry-leading standards for security and performance, providing a secure and fast way for each device.

If you want to learn more about Hoko, you can send us an email or register directly.

(or simply check our detailed guide for Google's App links)

iOS 9 Learning Series: Universal links to iOS 9 (Universal links)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.