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

Source: Internet
Author: User
<span id="Label3"></p><p style="white-space: normal;"><p style="white-space: normal;">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.</p></p><p style="white-space: normal;"><p style="white-space: normal;">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.</p></p><p style="white-space: normal;"><p style="white-space: normal;"><span style="color: #00b050;"><strong>What is a generic link?</strong></span></p></p><p style="white-space: normal;"><p style="white-space: normal;">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.</p></p><p style="white-space: normal;"><p style="white-space: normal;">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).</p></p><p style="white-space: normal;"><p style="white-space: normal;"><span style="color: #00b050;"><strong>Ready to use generic links</strong></span></p></p><p style="white-space: normal;"><p style="white-space: normal;">Implementing generic links is not difficult, but first you must follow some Prerequisites. As follows:</p></p> <ul class=" list-paddingleft-2" style="width: 1013.640625px; white-space: normal;"> <ul class=" list-paddingleft-2" style="width: 1013.640625px; white-space: normal;"> <li><p>Have a registered domain name</p></li> <li><p>Access domain names via SSL</p></li> <li><p>Support for uploading a JSON file to your domain</p></li> <li><p>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.</p></li> <li><p>At least Xcode 7 Beta 2 [download]</p></li> </ul> </ul><p style="white-space: normal;"><p style="white-space: normal;">If you have one, follow the 3 steps below.</p></p><p style="white-space: normal;"><p style="white-space: normal;"><strong>1. Add domain name to capabilities</strong></p></p><p style="white-space: normal;"><p style="white-space: normal;">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.).</p></p><p style="white-space: normal; text-align: center;"><p style="white-space: normal; text-align: center;"></p></p><p style="white-space: normal; text-align: center;"><p style="white-space: normal; text-align: center;">Add all domain names with applinks: prefix and don't forget to include all possible subdomains *</p></p><p style="white-space: normal;"><p style="white-space: normal;">This will enable your APP to request a special JSON file from your domain Apple-app-site-association. <strong>When you start the APP for the first time,</strong> 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.</p></p><p style="white-space: normal;"><p style="white-space: normal;"><strong>2. Uploading apple-app-site-association files</strong></p></p><p style="white-space: normal;"><p style="white-space: normal;">The file must exist and can be accessed using <strong>SSL</strong> for security reasons through a <strong>get</strong> Request. You can open a text editor and write a simple <strong>JSON</strong> format like this:</p></p> <table border="0" cellspacing="0" cellpadding="0"> <tbody> <tr> <td class="gutter">12345678910</td> <td class="code"><code class="js plain"><code class="js plain">{</code></code><code class="js spaces"><code class="js spaces">  </code></code><code class="js string"><code class="js string">"applinks"</code></code><code class="js plain"><code class="js plain">: {</code></code><code class="js spaces"><code class="js spaces">    </code></code><code class="js string"><code class="js string">"apps"</code></code><code class="js plain"><code class="js plain">: [],</code></code><code class="js spaces"><code class="js spaces">    </code></code><code class="js string"><code class="js string">"details"</code></code><code class="js plain"><code class="js plain">: {</code></code><code class="js spaces"><code class="js spaces">      </code></code><code class="js string"><code class="js string">"TBEJCS6FFP.com.domain.App"</code></code><code class="js plain"><code class="js plain">: {</code></code><code class="js spaces"><code class="js spaces">        </code></code><code class="js string"><code class="js string">"paths"</code></code><code class="js plain"><code class="js plain">:[ </code></code><code class="js string"><code class="js string">"*"</code></code><code class="js plain"><code class="js plain">]</code></code><code class="js spaces"><code class="js spaces">      </code></code><code class="js plain"><code class="js plain">}</code></code><code class="js spaces"><code class="js spaces">    </code></code><code class="js plain"><code class="js plain">}</code></code><code class="js spaces"><code class="js spaces">  </code></code><code class="js plain"><code class="js plain">}</code></code><code class="js plain"><code class="js plain">}</code></code></td> </tr> </tbody> </table><p style="white-space: normal;"><p style="white-space: normal;">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.</p></p><p style="white-space: normal;"><p style="white-space: normal;">You may want to know <span style="color: #953734;">where TBEJCS6FFP.com.domain.App came from and basically, it is the bundle ID that joins your team's identity <span style="color: #953734;">. You can get your team logo from your [apple Development Account Page]:</span> </span></p></p><p style="white-space: normal; text-align: center;"><p style="white-space: normal; text-align: center;"></p></p><p style="white-space: normal; text-align: center;"><p style="white-space: normal; text-align: center;">This page has your team logo and you can copy and paste it into the apple-app-site-association file.</p></p><p style="white-space: normal;"><p style="white-space: normal;">Bundle IDs can be found in the Project's target-general:</p></p><p style="white-space: normal; text-align: center;"><p style="white-space: normal; text-align: center;"></p></p><p style="white-space: normal; text-align: center;"><p style="white-space: normal; text-align: center;">Check the General tab and copy and paste the bundle ID into the apple-app-site-association file</p></p><p style="white-space: normal;"><p style="white-space: normal;">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.</p></p><p style="white-space: normal;"><p style="white-space: normal;"><strong>3. Working with generic links in the APP</strong></p></p><p style="white-space: normal;"><p style="white-space: normal;">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.</p></p> <table border="0" cellspacing="0" cellpadding="0"> <tbody> <tr> <td class="gutter">123456789101112131415161718192021222324252627282930313233343536</td> <td class="code"><code class="js plain"><code class="js plain">import UIKit</code></code><code class="js plain"><code class="js plain">extension AppDelegate {</code></code><code class="js spaces"><code class="js spaces">    </code></code><code class="js plain"><code class="js plain">func application(application: UIApplication, continueUserActivity userActivity: NSUserActivity, restorationHandler: ([AnyObject]?) -> Void) -> Bool {</code></code><code class="js spaces"><code class="js spaces">        </code></code><code class="js keyword"><code class="js keyword">if</code></code><code class="js plain"><code class="js plain">userActivity.activityType == NSUserActivityTypeBrowsingWeb {</code></code><code class="js spaces"><code class="js spaces">            </code></code><code class="js plain"><code class="js plain">let webpageURL = userActivity.webpageURL! </code></code><code class="js comments"><code class="js comments">// Always exists</code></code><code class="js spaces"><code class="js spaces">            </code></code><code class="js keyword"><code class="js keyword">if</code></code> <code class="js plain"><code class="js plain">!handleUniversalLink(URL: webpageURL) {</code></code><code class="js spaces"><code class="js spaces">                </code></code><code class="js plain"><code class="js plain">UIApplication.sharedApplication().openURL(webpageURL)</code></code><code class="js spaces"><code class="js spaces">            </code></code><code class="js plain"><code class="js plain">}</code></code><code class="js spaces"><code class="js spaces">        </code></code><code class="js plain"><code class="js plain">}</code></code><code class="js spaces"><code class="js spaces">        </code></code><code class="js keyword"><code class="js keyword">return</code></code><code class="js keyword"><code class="js keyword">true</code></code><code class="js spaces"><code class="js spaces">    </code></code><code class="js plain"><code class="js plain">}</code></code><code class="js spaces"><code class="js spaces">    </code></code><code class="js spaces"><code class="js spaces">    </code></code><code class="js plain"><code class="js plain">private func handleUniversalLink(URL url: NSURL) -> Bool {</code></code><code class="js spaces"><code class="js spaces">        </code></code><code class="js keyword"><code class="js keyword">if</code></code><code class="js plain"><code class="js plain">let components = NSURLComponents(URL: url, resolvingAgainstBaseURL: </code></code><code class="js keyword"><code class="js keyword">true</code></code><code class="js plain"><code class="js plain">), let host = components.host, let pathComponents = components.path?.pathComponents {</code></code><code class="js spaces"><code class="js spaces">            </code></code><code class="js keyword"><code class="js keyword">switch</code></code> <code class="js plain"><code class="js plain">host {</code></code><code class="js spaces"><code class="js spaces">            </code></code><code class="js keyword"><code class="js keyword">case</code></code><code class="js string"><code class="js string">"domain.com"</code></code><code class="js plain"><code class="js plain">:</code></code><code class="js spaces"><code class="js spaces">                </code></code><code class="js keyword"><code class="js keyword">if</code></code><code class="js plain"><code class="js plain">pathComponents.count >= 4 {</code></code><code class="js spaces"><code class="js spaces">                    </code></code><code class="js keyword"><code class="js keyword">switch</code></code> <code class="js plain"><code class="js plain">(pathComponents[0], pathComponents[1], pathComponents[2], pathComponents[3]) {</code></code><code class="js spaces"><code class="js spaces">                    </code></code><code class="js keyword"><code class="js keyword">case</code></code><code class="js plain"><code class="js plain">(</code></code><code class="js string"><code class="js string">"/"</code></code><code class="js plain"><code class="js plain">, </code></code><code class="js string"><code class="js string">"path"</code></code><code class="js plain"><code class="js plain">, </code></code><code class="js string"><code class="js string">"to"</code></code><code class="js plain"><code class="js plain">, let something):</code></code><code class="js spaces"><code class="js spaces">                        </code></code><code class="js keyword"><code class="js keyword">if</code></code> <code class="js plain"><code class="js plain">validateSomething(something) {</code></code><code class="js spaces"><code class="js spaces">                            </code></code><code class="js plain"><code class="js plain">presentSomethingViewController(something)</code></code><code class="js spaces"><code class="js spaces">                            </code></code><code class="js keyword"><code class="js keyword">return</code></code><code class="js keyword"><code class="js keyword">true</code></code><code class="js spaces"><code class="js spaces">                        </code></code><code class="js plain"><code class="js plain">}</code></code><code class="js spaces"><code class="js spaces">                    </code></code><code class="js keyword"><code class="js keyword">default</code></code><code class="js plain"><code class="js plain">:</code></code><code class="js spaces"><code class="js spaces">                        </code></code><code class="js keyword"><code class="js keyword">return</code></code><code class="js keyword"><code class="js keyword">false</code></code><code class="js spaces"><code class="js spaces">                    </code></code><code class="js plain"><code class="js plain">}</code></code><code class="js spaces"><code class="js spaces">                </code></code><code class="js plain"><code class="js plain">}</code></code><code class="js spaces"><code class="js spaces">            </code></code><code class="js keyword"><code class="js keyword">default</code></code><code class="js plain"><code class="js plain">:</code></code><code class="js spaces"><code class="js spaces">                </code></code><code class="js keyword"><code class="js keyword">return</code></code><code class="js keyword"><code class="js keyword">false</code></code><code class="js spaces"><code class="js spaces">            </code></code><code class="js plain"><code class="js plain">}</code></code><code class="js spaces"><code class="js spaces">            </code></code><code class="js spaces"><code class="js spaces">        </code></code><code class="js plain"><code class="js plain">}</code></code><code class="js spaces"><code class="js spaces">        </code></code><code class="js keyword"><code class="js keyword">return</code></code><code class="js keyword"><code class="js keyword">false</code></code><code class="js spaces"><code class="js spaces">    </code></code><code class="js plain"><code class="js plain">}</code></code><code class="js plain"><code class="js plain">}</code></code></td> </tr> </tbody> </table><p style="white-space: normal;"><p style="white-space: normal;">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.</p></p><p style="white-space: normal;"><p style="white-space: normal;">To make sure your APP can translate URLs into actual content, you need to do the following steps:</p></p> <ul class=" list-paddingleft-2" style="width: 1013.640625px; white-space: normal;"> <ul class=" list-paddingleft-2" style="width: 1013.640625px; white-space: normal;"> <li><p>Use [nsurlcomponents] to simply parse Webpageurl to host, such as Domain. com), The path consists of the same (such as ["/"], "path", "to" and "thezoo").</p></li> <li><p>Ensure that host is Recognized.</p></li> <li><p>Try to match pathcomponents to the APP's known Content.</p></li> <li><p>Verify that the content can actually be rendered.</p></li> <li><p>Renders the content to the User.</p></li> </ul> </ul><p style="white-space: normal;"><p style="white-space: normal;">If any of these steps fail, Apple recommends that your APP open webpageurl on Safari to show the Error.</p></p><p style="white-space: normal;"><p style="white-space: normal;">Summarize</p></p><p style="white-space: normal; text-align: center;"><p style="white-space: normal; text-align: center;"></p></p><p style="white-space: normal; text-align: center;"><p style="white-space: normal; text-align: center;">Overview of the workflow that is a generic link</p></p><p style="white-space: normal;"><p style="white-space: normal;"><span style="color: #00b050;"><strong>Disadvantages of Universal Links</strong></span></p></p><p style="white-space: normal;"><p style="white-space: normal;">Generic links are a good idea for developers, but there are some drawbacks that can lead to unpopular.</p></p><p style="white-space: normal;"><p style="white-space: normal;"><strong>Universal links are only available for IOS 9 +</strong></p></p><p style="white-space: normal;"><p style="white-space: normal;">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.</p></p><p style="white-space: normal;"><p style="white-space: normal;">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.</p></p><p style="white-space: normal;"><p style="white-space: normal;"><strong>Universal links are always returned to the page you created earlier</strong></p></p><p style="white-space: normal;"><p style="white-space: normal;">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.</p></p><p style="white-space: normal;"><p style="white-space: normal;">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.</p></p><p style="white-space: normal;"><p style="white-space: normal;"><strong>With generic links, developers must deploy a website to associate apps</strong></p></p><p style="white-space: normal;"><p style="white-space: normal;">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.</p></p><p style="white-space: normal;"><p style="white-space: normal;">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.</p></p><p style="white-space: normal;"><p style="white-space: normal;"><strong>The link between the APP and the website is done by the profile created and hosted on the Developer's Website.</strong></p></p><p><p>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.</p></p><p><p>iOS 9 Learning Series: Universal links to iOS 9 (Universal links)</p></p></span>

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.