Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Universal link in ios 9

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 318
    Comment on it

    Universal link in iOS9 is similar to Deep linking in that on tapping a link on a website the app is launched. But in universal link the app is opened directly without going through safari. It also works with the apps which make call to openURL: for redirecting to the app (like mail, messages etc).

    There are 3 steps to integrate Universal link to your app:

    1. Create apple-app-site-association file which contains information about URLs that the app can handle.
    2. Upload the apple-app-site-association file to HTTPS server.
    3. Handle universal links from within the app.

    Creating and uploading app association file

    App association file creates a trust relationship between app and website. We also need a com.apple.developer.associated-domains entitlement added to the iOS project which can be created easily by Xcode as we will see ahead.

    Below is an example apple-app-site-association file

    {
    
      "applinks": {
    
      "apps": [],
    
      "details": [
    
        {
    
          "appID": "A8TQ62WUAMZ.com.mycompany.myapp",
    
          "paths": [ "/path/abc/", "/images/folder/xyz/*"]
    
        },
    
        {
    
          "appID": "ASDF3312.com.mycompany.myapp",
    
          "paths": [ "*" ]
    
        }
    
       ]
    
      }
    
    } 

    Here apps key must be present and its value must be an empty array, appID is the team ID or app ID prefix followed by the bundle ID and paths is an array of strings that specify paths of website that are supported by the app. If we want some part should not be supported by the app we can put a NOT before the path.

     

    For ex "/videos/wwdc/2010/*" will not be included in following paths array :

    "paths": [ "/path/abc/", "NOT /path/images/aaa/*", "/path/images/bbb/*"]

    • * can be used to specify entire website.
    • specific URL can be included to specify a particular link. Like- /path/abc/
    • * can be appended to a path to specify a particular section of the website. Like- /path/images/bbb/*
    • ? can be used to match a single character. Like- /path/*/abc/201?/page

     

    Don't add .json extension to the file and upload it to ROOT directory of the HTTPS server in the .well-known subdirectory. The file needs to be accessible via HTTPS-without any redirects-at https://<domain>/apple-app-site-association or https://<domain>/.well-known/apple-app-site-association

     

    Handling Universal links from app

     

    To handle Universal links we have to do the following :

    • Add entitlement that includes supported domains
    • Handle in App delegate when the app is launched by Universal link

    To include supported domains enable associated domains from xcode and enter your domain name prefixed with applinks: in Domains field such as applinks:www.mywebsite.com. You can add multiple entries to about 20-30 domains.

    When an app launches by tapping universal link either application:didFinishLaunchingWithOptions: or application:continueUserActivity:restorationHandler: method is invoked depending on the app state. In both of these methods, NSUserActivity object is received which contains activityType with value NSUserActivityTypeBrowsingWeb. The activity object's webPageUrl property contains the URL that the user is accessing. We can useAPI'sNSURLComponents's to handle the components of the URL.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: