{"id":2427,"date":"2017-02-07T15:33:39","date_gmt":"2017-02-07T10:03:39","guid":{"rendered":"https:\/\/www.innovationm.com\/blog\/?p=2427"},"modified":"2017-02-09T13:14:46","modified_gmt":"2017-02-09T07:44:46","slug":"deferred-deep-linking-in-ios-with-universal-link","status":"publish","type":"post","link":"https:\/\/www.innovationm.com\/blog\/deferred-deep-linking-in-ios-with-universal-link\/","title":{"rendered":"Deferred Deep Linking in iOS Swift 3.0 with Universal Link"},"content":{"rendered":"<h2>What is the Problem?<\/h2>\n<p>Guess if we have a mobile website as well as mobile App and an user\u00a0share the url of any content on our website to a user who have our application installed on his\/hers phone. If the user click on the link it will be opened in the web browser, but the same content is also available on the App and if it was opened on the App the user experience should have been better.<\/p>\n<h2>What deep link can do?<\/h2>\n<p>By using the deep link we can link the content inside of our application directly to the web url. So if an user sends a link to his\/hers friends they can open the same content in the mobile application just by clicking the url.<\/p>\n<h2>Types of deep links<\/h2>\n<ol>\n<li>Traditional Deep Link<\/li>\n<li>Deferred Deep Link<\/li>\n<li>Contextual Deep Link<\/li>\n<\/ol>\n<h2>Traditional Deep Linking<\/h2>\n<p>In traditional deep linking when an user click on any url it will redirect to the corresponding content in the application if the application is installed on the device otherwise it will open the url in web browser. In the case when user does not have application installed on his\/hers device and open the link and from web browser it goes to store and installed the application then open it, he\/she will land on the home\u00a0page of the application rather than the content page of the url.<\/p>\n<p><a href=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/02\/deep-link.jpg\"><img fetchpriority=\"high\" decoding=\"async\" class=\" wp-image-2440 alignnone\" src=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/02\/deep-link.jpg\" alt=\"Deep Linking\" width=\"723\" height=\"419\" srcset=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/02\/deep-link.jpg 864w, https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/02\/deep-link-300x174.jpg 300w, https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/02\/deep-link-624x361.jpg 624w\" sizes=\"(max-width: 723px) 100vw, 723px\" \/><\/a><\/p>\n<h2>Deferred Deep Linking<\/h2>\n<p>In Traditional deep linking we have a drawback of losing the link when user do not have App installed on his\/hers device. In deferred deep linking we solve this problem and when user install the App for first time from a link and open the App we redirect him\/her\u00a0to the content according to the url.<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/02\/deferred-deep-link.jpg\"><img decoding=\"async\" class=\"alignnone size-full wp-image-2441\" src=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/02\/deferred-deep-link.jpg\" alt=\"Deferred Deep Linking\" width=\"864\" height=\"500\" srcset=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/02\/deferred-deep-link.jpg 864w, https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/02\/deferred-deep-link-300x174.jpg 300w, https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/02\/deferred-deep-link-624x361.jpg 624w\" sizes=\"(max-width: 864px) 100vw, 864px\" \/><\/a><\/p>\n<h2>Contextual\u00a0Deep Linking<\/h2>\n<p>Contextual deep linking is much similar to Deferred deep linking. Addition to Deferred deep linking in Contextual deep linking we store user information and pass it to our mobile App so that we can restore his\/hers state in mobile App. In this deep linking we not only pass data about where to land in the App but also record the information about the user including who they are, where they are referred from, who referred them or which promotion code they want to apply.<\/p>\n<h2>URL Scheme<\/h2>\n<p>URL Scheme let you define a custom protocol to let other application communicate with your application. To let other applications communicate with your App you must create an appropriately formatted URL and add support in your application. To implement\u00a0<strong>URL Scheme<\/strong> you must tell the system to open it in your application and handle the incoming URL in your application. This URL Scheme looks like other URL Scheme like <strong>http:\/\/, ftp:\/\/, mailto:\/\/, tel:\/\/ etc.<\/strong> You can create your custom URL protocol like <strong><em>yourapp:\/\/open-home-page<\/em>.\u00a0<\/strong>Any application can open your application with this scheme by calling openURL. For Example if your custom URL is <strong><em>yourapp:\/\/<\/em><\/strong> then following code will open your App:<\/p>\n<pre class=\"lang:swift decode:true\">let appUrl = URL(string: \"youapp:\/\/page-to-open\")\r\nUIApplication.shared.openURL(appUrl!)<\/pre>\n<h3>Register your Custom URL<\/h3>\n<p>To Register your application for URL Scheme support you have to include the\u00a0<strong>CFBundleURLTypes\u00a0<\/strong>key in your <strong>Info.plist\u00a0<\/strong>file. This key will have array of dictionary with following keys:<\/p>\n<ol>\n<li>CFBundleURLName: It is a string containing abstract name of the URL Scheme.<\/li>\n<li>CFBundleURLSchemes: It is an array containing the URL Scheme names.<\/li>\n<\/ol>\n<pre class=\"lang:xhtml decode:true\">&lt;key&gt;CFBundleURLTypes&lt;\/key&gt;\r\n&lt;array&gt;\r\n\u00a0 &lt;dict&gt;\r\n\u00a0\u00a0 &lt;key&gt;CFBundleURLName&lt;\/key&gt;\r\n\u00a0\u00a0 &lt;string&gt;com.yourapp&lt;\/string&gt;\r\n\u00a0\u00a0 &lt;key&gt;CFBundleURLSchemes&lt;\/key&gt;\r\n\u00a0\u00a0 &lt;array&gt;\r\n\u00a0\u00a0\u00a0 &lt;string&gt;yourapp&lt;\/string&gt;\r\n\u00a0\u00a0 &lt;\/array&gt;\r\n\u00a0 &lt;\/dict&gt;\r\n&lt;\/array&gt;<\/pre>\n<h3>Handling the URL\u00a0Request<\/h3>\n<p>When any application request your custom URL your App must handle the URL to open corresponding content. On any request to your custom URL will call AppDelegate&#8217;s method\u00a0<em>application(_:open:options:),\u00a0<\/em>so you have to implement this method in your AppDelegate. Refer following code snippet:<\/p>\n<pre class=\"lang:swift decode:true\">func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -&gt; Bool {\r\n\u00a0 print(url)\r\n  \/\/ Take decision according to URL\r\n\u00a0 return true\r\n}<\/pre>\n<p>If your application is not running (Killed) then it will first launch your application and then call the open url method. In this case the following sequence of methods will be executed:<\/p>\n<p><a href=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/02\/uri-scheme.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-2443\" src=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/02\/uri-scheme.png\" alt=\"URL Scheme in Killed\" width=\"1224\" height=\"1614\" srcset=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/02\/uri-scheme.png 1224w, https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/02\/uri-scheme-228x300.png 228w, https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/02\/uri-scheme-777x1024.png 777w, https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/02\/uri-scheme-624x823.png 624w\" sizes=\"(max-width: 1224px) 100vw, 1224px\" \/><\/a><\/p>\n<p>If your application is running but is in background or suspended state then following method sequence will be called:<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/02\/url-scheme-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2444\" src=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/02\/url-scheme-1.png\" alt=\"URL Scheme in Foreground\" width=\"1230\" height=\"933\" srcset=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/02\/url-scheme-1.png 1230w, https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/02\/url-scheme-1-300x228.png 300w, https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/02\/url-scheme-1-1024x777.png 1024w, https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/02\/url-scheme-1-624x473.png 624w\" sizes=\"(max-width: 1230px) 100vw, 1230px\" \/><\/a><\/p>\n<h2>Universal Link<\/h2>\n<p>The problem with URL Scheme is that when an user share a url the url is of a webpage which support http protocol and when an user click on it first the webpage will be open in web browser then in the web browser our web app has to make request to our custom url to open the content in the mobile app. So in Custom URL Scheme web browser has to be launched before we can open the content in our mobile App.<\/p>\n<p style=\"text-align: left;\">From iOS 9.0 Apple introduced Universal Link as a solution of this problem. Universal Link support direct linking between web page url and mobile app. When any user click on a url then iOS\u00a0first check if there is any application which support this url if yes then it will open that corresponding Application otherwise the url will be opened in web browser.<\/p>\n<p style=\"text-align: left;\">To support Universal Link you have to follow these three steps:<\/p>\n<ol>\n<li style=\"text-align: left;\">Create an <em>apple-app-site-association<\/em> file.<\/li>\n<li style=\"text-align: left;\">Upload this file to your HTTPS server.<\/li>\n<li style=\"text-align: left;\">Handle universal link in your App.<\/li>\n<\/ol>\n<h3>Create apple-app-site-association File<\/h3>\n<p>The <em>apple-app-site-association\u00a0<\/em>file is used to create trust relationship between your mobile application and your server.\u00a0This file contains simple json data\u00a0(Do not add .json extension in file name) with following format:<\/p>\n<pre class=\"lang:default decode:true\">{\r\n\u00a0 \"applinks\": {\r\n\u00a0\u00a0 \"apps\": [],\r\n\u00a0\u00a0 \"details\": [\r\n\u00a0\u00a0\u00a0 {\r\n\u00a0\u00a0\u00a0\u00a0 \"appID\": \"9JA89QQLNQ.com.apple.wwdc\",\r\n\u00a0\u00a0\u00a0\u00a0 \"paths\": [ \"\/wwdc\/news\/\", \"\/videos\/wwdc\/2015\/*\"]\r\n\u00a0\u00a0\u00a0 },\r\n\u00a0\u00a0\u00a0 {\r\n\u00a0\u00a0\u00a0\u00a0 \"appID\": \"ABCD1234.com.apple.wwdc\",\r\n\u00a0\u00a0\u00a0\u00a0 \"paths\": [ \"*\" ]\r\n\u00a0\u00a0\u00a0 }\r\n\u00a0 ]\r\n\u00a0}\r\n}<\/pre>\n<p>In this json the\u00a0<em>apps\u00a0<\/em>key must be present and it&#8217;s value must be an empty array. The\u00a0<em>details\u00a0<\/em>key is an array of dictionaries. Each dictionary contains\u00a0<em>appId\u00a0<\/em>and\u00a0<em>paths\u00a0<\/em>keys. The value of key <i>appId\u00a0<\/i>is your apple Id or team Id in the concatination of your bundle identifier. In Above example the first value of\u00a0<em>appId<\/em> has\u00a0<strong>9JA89QQLNQ\u00a0<\/strong>as apple Id and\u00a0<strong>com.apple.wwdc\u00a0<\/strong>as bundle identifier. You have to replace these values with your own apple Id and bundle identifiers. The value of key\u00a0<em>paths\u00a0<\/em>is an array of string that defines the parts of your website which your application can handle. In first dictionary it will open your application if url have\u00a0<em>\/www\/news\/\u00a0<\/em>in the url or it has any url starting with\u00a0<em>\/video\/wwdc\/2015\/<\/em>.<\/p>\n<p>Use * to link your whole website or use it after a path to support some part of your website.<\/p>\n<p>You can also use <strong>NOT\u00a0<\/strong>to exclude any url from universal link like:\u00a0<em><code class=\"code-voice\">\"paths\": [ \"\/wwdc\/news\/\", \"NOT \/videos\/wwdc\/2010\/*\", \"\/videos\/wwdc\/201?\/*\"].<\/code><\/em><\/p>\n<h3>Upload\u00a0apple-app-site-association File to Server<\/h3>\n<p>To support Universal Link your server must support https protocol. Once you create the file you have copy this file to the root directory of your server or the\u00a0<em>.well-known <\/em>subdirectory. This file should be accessible with https protocol without any redirection at\u00a0<code class=\"code-voice\">https:\/\/&lt;your_domain&gt;\/apple-app-site-association<\/code> or <code class=\"code-voice\">https:\/\/&lt;your_domain&gt;\/.well-known\/apple-app-site-association<\/code><\/p>\n<h3>Handle Universal Link in your App<\/h3>\n<p>To handle universal link in your application first you have to add an entitlement file with supported urls in your application. To do so open Xcode, Select your project, Goto Capabilities and find Associated Domain section. Turn on this capability and add an entry for each domain your app supports with a prefix of\u00a0<em>applinks:<\/em><\/p>\n<p><a href=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/02\/Screen-Shot-2017-02-04-at-5.11.03-PM.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-2451 size-full\" src=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/02\/Screen-Shot-2017-02-04-at-5.11.03-PM.png\" alt=\"App Links\" width=\"903\" height=\"263\" srcset=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/02\/Screen-Shot-2017-02-04-at-5.11.03-PM.png 903w, https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/02\/Screen-Shot-2017-02-04-at-5.11.03-PM-300x87.png 300w, https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/02\/Screen-Shot-2017-02-04-at-5.11.03-PM-624x182.png 624w\" sizes=\"(max-width: 903px) 100vw, 903px\" \/><\/a><\/p>\n<p>Now you have to implement\u00a0<em>application(_:continue:restorationHandler:)\u00a0<\/em>in your AppDelegate file. This method will be called when user click on link which your supports.<\/p>\n<pre class=\"lang:swift decode:true\">func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -&gt; Void) -&gt; Bool {\r\n\u00a0 let url = userActivity.webpageURL!\r\n\u00a0 print(url)\r\n\u00a0 \/\/ Take decision according to URL\r\n\u00a0 return true\r\n}<\/pre>\n<h2>Problem with Universal Link<\/h2>\n<p>In Universal link iOS also check the recent chioce of the user that whether to open the url in mobile application or web browser. When an user open the url in your application he\/she can also open the url in Safari by tapping the\u00a0breadcrumb button at the right side of the status bar.<\/p>\n<p><a href=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/02\/breadcrumb-button.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-2452 aligncenter\" src=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/02\/breadcrumb-button.png\" alt=\"breadcrumb-button\" width=\"375\" height=\"75\" srcset=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/02\/breadcrumb-button.png 375w, https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/02\/breadcrumb-button-300x60.png 300w\" sizes=\"(max-width: 375px) 100vw, 375px\" \/><\/a><\/p>\n<p>Once user click on the\u00a0breadcrumb button, iOS will remember the choice of the user and next time it will always open the link in Safari. To overcome this situation we have to add a Smart Banner to our web page so that when iOS open the application in Safari user can go back to application by Smart Banner. Once user open the Application using Smart Banner iOS will remember the choice of user and next time the link will be opened in Application.<\/p>\n<h2>Smart Banner<\/h2>\n<p>We can use smart banner in our webpage to let user install or open our mobile application directly from webpage. The banner intelligently changes it&#8217;s action depending upon whether the Application is installed on the device or not.<\/p>\n<p>To add a Smart Banner to webpage use following meta tag:<\/p>\n<pre class=\"lang:xhtml decode:true\">&lt;meta name=\"apple-itunes-app\" content=\"app-id=myAppStoreID, affiliate-data=myAffiliateData, app-argument=myURL\"&gt;<\/pre>\n<p>In this tag you have enter following parameters:<\/p>\n<ol>\n<li><em>app-id:\u00a0<\/em>It is you application&#8217;s unique identifier at App Store. You can find it\u00a0<a href=\"https:\/\/linkmaker.itunes.apple.com\/en-us\" target=\"_blank\">Here<\/a>. Search your app and the iPhone App Link.\u00a0Your app ID is the nine-digit number in between <em><code>id<\/code><\/em> and <em><code>?mt<\/code><\/em>.<\/li>\n<li><em>affiliate-data:\u00a0<\/em>If you&#8217;re an iTunes affiliate you can add your affiliate string here. It is an Optional field.<\/li>\n<li><em>app-argument<\/em>: Here you have to give the url that will be passed to your mobile App when user open the application by Smart Banner.<\/li>\n<\/ol>\n<p>Here is the Smart Banner When App is not Installed:<\/p>\n<p><a href=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/02\/smartbanner-view.png\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-2448 aligncenter\" src=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/02\/smartbanner-view.png\" alt=\"Smart Banner\" width=\"430\" height=\"95\" srcset=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/02\/smartbanner-view.png 736w, https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/02\/smartbanner-view-300x66.png 300w, https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/02\/smartbanner-view-624x138.png 624w\" sizes=\"(max-width: 430px) 100vw, 430px\" \/><\/a><\/p>\n<p>When user click View he\/she will be redirected to App Store.<\/p>\n<p>Here is the Smart Banner When App is Installed:<\/p>\n<p><a href=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/02\/smartbanner-open.png\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-2449 aligncenter\" src=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/02\/smartbanner-open.png\" alt=\"Smart Banner\" width=\"428\" height=\"50\" srcset=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/02\/smartbanner-open.png 750w, https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/02\/smartbanner-open-300x35.png 300w, https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/02\/smartbanner-open-624x73.png 624w\" sizes=\"(max-width: 428px) 100vw, 428px\" \/><\/a><\/p>\n<p>When user click OPEN he\/she will be redirected to your mobile app and next time when he\/she click on link it will directly open in Mobile App.<\/p>\n<h2>Implementing Deferred Deep Linking<\/h2>\n<p>Unitl now we have two methods to open the application and getting the URL when application is installed on user&#8217;s device, But what if user click on link and the application is not installed on device. It will be opened on web browser, user will install the application but when he\/she launches the application we will not get any url on which we can take decision to land him\/her on the correct page. For this problem we have to implement some mechanism by which we can share the url between the web browser and the Mobile Application.<\/p>\n<p>To share the data between Safari and Mobile App we will use <strong>SFSafariViewController.\u00a0<\/strong>SFSafariViewController was introduced in iOS 9.0 and it supports sharing of web page data like cookies between applications. So what we are gonna do is to store the url in the cookie when user open the url in web browser and he\/she lanunches the application we will open an simple page which will check the cookie and if cookie is present it will launch our application by using URL Scheme so that we can make a decision.<\/p>\n<p>The complete flow of the application is shown in the following flow diagram:<\/p>\n<p><a href=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/02\/Untitled-Diagram-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-2434 aligncenter\" src=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/02\/Untitled-Diagram-1.png\" alt=\"Deferred Deep Linking\" width=\"652\" height=\"762\" srcset=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/02\/Untitled-Diagram-1.png 652w, https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/02\/Untitled-Diagram-1-257x300.png 257w, https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/02\/Untitled-Diagram-1-624x729.png 624w\" sizes=\"(max-width: 652px) 100vw, 652px\" \/><\/a><\/p>\n<h2>Safari View Controller<\/h2>\n<p>Before reading the cookie using <strong>SFSafariViewController\u00a0<\/strong>you have to first store the url (or token) in the cookie.\u00a0So in the share url page you have to store the url (token) in the cookie of your web browser. Use following JavaScript Code to store the token in cookie:<\/p>\n<pre class=\"lang:js decode:true\">custom = \"yourapp:\/\/&lt;your_token&gt;\";\r\nvar now = new Date();\r\nvar time = now.getTime();\r\nvar expireTime = time + 1000*3600;\r\nnow.setTime(expireTime);\r\ndocument.cookie = 'yourKey=' + custom + ';expires='+now.toGMTString()+';domain=&lt;your_domain&gt;';<\/pre>\n<p>Now to read the cookie we have to launch the <strong>SFSafariViewController<\/strong>. Use following code to launch this controller:<\/p>\n<pre class=\"lang:swift decode:true\">let redirectUrl = URL(string: \"http:\/\/&lt;youwebsite&gt;\/redirect.html\")!\r\n\r\nlet safariViewController = SFSafariViewController(url: redirectUrl)\r\nsafariViewController.delegate = self\r\nsafariViewController.modalPresentationStyle = .overCurrentContext\r\nsafariViewController.view.alpha = 0.05\r\n\r\npresent(safariViewController, animated: false, completion: nil)<\/pre>\n<p>You have to import\u00a0<strong><span class=\"s1\">SafariServices\u00a0<\/span><\/strong><span class=\"s1\">framework to use <strong>SFSafariViewController<\/strong>.<\/span><\/p>\n<p>Now you have to implement the\u00a0<strong>SFSafariViewControllerDelegate<\/strong> in your view controller. This delegate have two methods you have to implement and then dismiss the Safari View Controller.<\/p>\n<pre class=\"lang:swift decode:true\">extension ViewController: SFSafariViewControllerDelegate {\r\n\r\n\u00a0 func safariViewController(_ controller: SFSafariViewController, didCompleteInitialLoad didLoadSuccessfully: Bool) {\r\n\u00a0\u00a0 controller.dismiss(animated: false, completion: nil)\r\n\u00a0 }\r\n\r\n\u00a0 func safariViewControllerDidFinish(_ controller: SFSafariViewController) {\r\n\u00a0\u00a0 controller.dismiss(animated: false, completion: nil)\r\n\u00a0 }\r\n\r\n}<\/pre>\n<p>Now in url we have used\u00a0<strong>redirect.html<\/strong> which will be responsible reading the cookie and then calling our application by URL Scheme. Add following code in the\u00a0<strong>redirect.html\u00a0<\/strong>file to read and redirect.<\/p>\n<pre class=\"lang:js decode:true\">&lt;script&gt;\r\n\r\n\u00a0 function getCookie(name) {\r\n\u00a0\u00a0 var re = new RegExp(name + \"=([^;]+)\");\r\n\u00a0\u00a0 var value = re.exec(document.cookie);\r\n\u00a0\u00a0 return (value != null) ? unescape(value[1]) : null;\r\n\u00a0 }\r\n\r\n\u00a0 var m = getCookie(\"yourKey\");\r\n\r\n\u00a0 if(m){\r\n\u00a0\u00a0 location.href = m;\r\n\u00a0 } else {\r\n\u00a0\u00a0 document.writeln(\"No Cookies...\");\r\n\u00a0 }\r\n\r\n&lt;\/script&gt;<\/pre>\n<p>That&#8217;s it. Hope you enjoyed reading it. \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>What is the Problem? Guess if we have a mobile website as well as mobile App and an user\u00a0share the url of any content on our website to a user who have our application installed on his\/hers phone. If the user click on the link it will be opened in the web browser, but the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2492,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,71,8,6],"tags":[184,185,160,183,178],"class_list":["post-2427","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ios","category-mobile","category-mobile-architecture-and-design","category-mobile-web-app","tag-deep-link","tag-deferred","tag-ios","tag-swift","tag-swift-3-0"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Deferred Deep Linking in iOS with Universal Link | InnovationM Blog<\/title>\n<meta name=\"description\" content=\"Deferred Deep Linking in iOS\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.innovationm.com\/blog\/deferred-deep-linking-in-ios-with-universal-link\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Deferred Deep Linking in iOS with Universal Link | InnovationM Blog\" \/>\n<meta property=\"og:description\" content=\"Deferred Deep Linking in iOS\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.innovationm.com\/blog\/deferred-deep-linking-in-ios-with-universal-link\/\" \/>\n<meta property=\"og:site_name\" content=\"InnovationM - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2017-02-07T10:03:39+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2017-02-09T07:44:46+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/02\/Deferred-Deep-Linking.png\" \/>\n\t<meta property=\"og:image:width\" content=\"902\" \/>\n\t<meta property=\"og:image:height\" content=\"501\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"InnovationM Admin\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"InnovationM Admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"11 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/deferred-deep-linking-in-ios-with-universal-link\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/deferred-deep-linking-in-ios-with-universal-link\\\/\"},\"author\":{\"name\":\"InnovationM Admin\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#\\\/schema\\\/person\\\/a831bf4602d69d1fa452e3de0c8862ed\"},\"headline\":\"Deferred Deep Linking in iOS Swift 3.0 with Universal Link\",\"datePublished\":\"2017-02-07T10:03:39+00:00\",\"dateModified\":\"2017-02-09T07:44:46+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/deferred-deep-linking-in-ios-with-universal-link\\\/\"},\"wordCount\":1874,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/deferred-deep-linking-in-ios-with-universal-link\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/wp-content\\\/uploads\\\/2017\\\/02\\\/Deferred-Deep-Linking.png\",\"keywords\":[\"Deep Link\",\"Deferred\",\"iOS\",\"Swift\",\"Swift 3.0\"],\"articleSection\":[\"iOS\",\"Mobile\",\"Mobile Architecture and Design\",\"Mobile Web App\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/deferred-deep-linking-in-ios-with-universal-link\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/deferred-deep-linking-in-ios-with-universal-link\\\/\",\"url\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/deferred-deep-linking-in-ios-with-universal-link\\\/\",\"name\":\"Deferred Deep Linking in iOS with Universal Link | InnovationM Blog\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/deferred-deep-linking-in-ios-with-universal-link\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/deferred-deep-linking-in-ios-with-universal-link\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/wp-content\\\/uploads\\\/2017\\\/02\\\/Deferred-Deep-Linking.png\",\"datePublished\":\"2017-02-07T10:03:39+00:00\",\"dateModified\":\"2017-02-09T07:44:46+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#\\\/schema\\\/person\\\/a831bf4602d69d1fa452e3de0c8862ed\"},\"description\":\"Deferred Deep Linking in iOS\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/deferred-deep-linking-in-ios-with-universal-link\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/deferred-deep-linking-in-ios-with-universal-link\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/deferred-deep-linking-in-ios-with-universal-link\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/wp-content\\\/uploads\\\/2017\\\/02\\\/Deferred-Deep-Linking.png\",\"contentUrl\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/wp-content\\\/uploads\\\/2017\\\/02\\\/Deferred-Deep-Linking.png\",\"width\":902,\"height\":501},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/deferred-deep-linking-in-ios-with-universal-link\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Deferred Deep Linking in iOS Swift 3.0 with Universal Link\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/\",\"name\":\"InnovationM - Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#\\\/schema\\\/person\\\/a831bf4602d69d1fa452e3de0c8862ed\",\"name\":\"InnovationM Admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g\",\"caption\":\"InnovationM Admin\"},\"sameAs\":[\"http:\\\/\\\/www.innovationm.com\\\/\"],\"url\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/author\\\/innovationmadmin\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Deferred Deep Linking in iOS with Universal Link | InnovationM Blog","description":"Deferred Deep Linking in iOS","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.innovationm.com\/blog\/deferred-deep-linking-in-ios-with-universal-link\/","og_locale":"en_US","og_type":"article","og_title":"Deferred Deep Linking in iOS with Universal Link | InnovationM Blog","og_description":"Deferred Deep Linking in iOS","og_url":"https:\/\/www.innovationm.com\/blog\/deferred-deep-linking-in-ios-with-universal-link\/","og_site_name":"InnovationM - Blog","article_published_time":"2017-02-07T10:03:39+00:00","article_modified_time":"2017-02-09T07:44:46+00:00","og_image":[{"width":902,"height":501,"url":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/02\/Deferred-Deep-Linking.png","type":"image\/png"}],"author":"InnovationM Admin","twitter_misc":{"Written by":"InnovationM Admin","Est. reading time":"11 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.innovationm.com\/blog\/deferred-deep-linking-in-ios-with-universal-link\/#article","isPartOf":{"@id":"https:\/\/www.innovationm.com\/blog\/deferred-deep-linking-in-ios-with-universal-link\/"},"author":{"name":"InnovationM Admin","@id":"https:\/\/www.innovationm.com\/blog\/#\/schema\/person\/a831bf4602d69d1fa452e3de0c8862ed"},"headline":"Deferred Deep Linking in iOS Swift 3.0 with Universal Link","datePublished":"2017-02-07T10:03:39+00:00","dateModified":"2017-02-09T07:44:46+00:00","mainEntityOfPage":{"@id":"https:\/\/www.innovationm.com\/blog\/deferred-deep-linking-in-ios-with-universal-link\/"},"wordCount":1874,"commentCount":0,"image":{"@id":"https:\/\/www.innovationm.com\/blog\/deferred-deep-linking-in-ios-with-universal-link\/#primaryimage"},"thumbnailUrl":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/02\/Deferred-Deep-Linking.png","keywords":["Deep Link","Deferred","iOS","Swift","Swift 3.0"],"articleSection":["iOS","Mobile","Mobile Architecture and Design","Mobile Web App"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.innovationm.com\/blog\/deferred-deep-linking-in-ios-with-universal-link\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.innovationm.com\/blog\/deferred-deep-linking-in-ios-with-universal-link\/","url":"https:\/\/www.innovationm.com\/blog\/deferred-deep-linking-in-ios-with-universal-link\/","name":"Deferred Deep Linking in iOS with Universal Link | InnovationM Blog","isPartOf":{"@id":"https:\/\/www.innovationm.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.innovationm.com\/blog\/deferred-deep-linking-in-ios-with-universal-link\/#primaryimage"},"image":{"@id":"https:\/\/www.innovationm.com\/blog\/deferred-deep-linking-in-ios-with-universal-link\/#primaryimage"},"thumbnailUrl":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/02\/Deferred-Deep-Linking.png","datePublished":"2017-02-07T10:03:39+00:00","dateModified":"2017-02-09T07:44:46+00:00","author":{"@id":"https:\/\/www.innovationm.com\/blog\/#\/schema\/person\/a831bf4602d69d1fa452e3de0c8862ed"},"description":"Deferred Deep Linking in iOS","breadcrumb":{"@id":"https:\/\/www.innovationm.com\/blog\/deferred-deep-linking-in-ios-with-universal-link\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.innovationm.com\/blog\/deferred-deep-linking-in-ios-with-universal-link\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.innovationm.com\/blog\/deferred-deep-linking-in-ios-with-universal-link\/#primaryimage","url":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/02\/Deferred-Deep-Linking.png","contentUrl":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/02\/Deferred-Deep-Linking.png","width":902,"height":501},{"@type":"BreadcrumbList","@id":"https:\/\/www.innovationm.com\/blog\/deferred-deep-linking-in-ios-with-universal-link\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.innovationm.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Deferred Deep Linking in iOS Swift 3.0 with Universal Link"}]},{"@type":"WebSite","@id":"https:\/\/www.innovationm.com\/blog\/#website","url":"https:\/\/www.innovationm.com\/blog\/","name":"InnovationM - Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.innovationm.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.innovationm.com\/blog\/#\/schema\/person\/a831bf4602d69d1fa452e3de0c8862ed","name":"InnovationM Admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g","caption":"InnovationM Admin"},"sameAs":["http:\/\/www.innovationm.com\/"],"url":"https:\/\/www.innovationm.com\/blog\/author\/innovationmadmin\/"}]}},"_links":{"self":[{"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/posts\/2427","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/comments?post=2427"}],"version-history":[{"count":0,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/posts\/2427\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/media\/2492"}],"wp:attachment":[{"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/media?parent=2427"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/categories?post=2427"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/tags?post=2427"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}