WWDC 2015

Seamless linking to your app

Deep linking becomes so important for iOS 9 as it will be connecting with brand new search mechanism in iOS 9.

This video introduces universal links to the apps when they tap links on the websites.

Demo (WWDC app) tapping website links -> native app detail page

  • have your app handle link to your website
  • have your website link to your app
  • help your users log into you app
  • Linking to your app *Custom URL schemes
    • apps communicate with each others
    • Don't always map to your app
    • Don't work without app installed
    • Don't protet users' privacy!

Breakdown of a universal link

iOS looks for

  • http/https scheme
  • domain
  • path or path prefix
  • above not match -> safari

URLQueryItem to assess url easily

Getting server ready

  • apple-app-site-association json file
    {
      "applinks": {
          "apps": [],
          "details": {
              "9JA89QQLNQ.com.apple.wwdc": {
                  "paths":[ "/wwdc/news/,
                          "/videos/wwdc/2015/*"] 
              }
          }
      }
    }
    
  • Generate an SSL certificate (not by Apple)
  • Sign the json file with ssl
openssl smime \
-sign \
-nodetach \
- in "unsigned.json"
- out "apple-app-site-association"

iOS 9 seed no need to sign the json

  • create the file
  • upload to the server

Getting your app ready

func application(application: UIApplication, continueUserActivity userActivity: NSUserActivity, restorationHandler:([AnyObject]!) -> void) -> Bool

var webpageURL:NSURL ?

check activityType == NSUserActivityTypeBrowsingWeb

breakdown the url and treat it like deep link

use NSURLComponent

Update entitlement with associated domain add domain as : applinks:www.example.com

Best practice

  • Validate input
  • fail gracefully (show a alert to inform user etc.)
  • send data over HTTPS

still need HTTP? Related session : Networking with NSURLSession

Demo to adopt universal links

Advantages of using universal links

  • NO Flashes or bouncing through Safari
  • NO code required of website
  • Gracefully failback to Safari
  • platform-indepentent
  • No extra server round-trips
  • Full user privacy protections

Smart app banners (nothing new)

Using safari saved password

available iOS 8

  • shared web credentials
    • association between app and website
      • add entitlement
        • add webcredential:example.com
      • add webcredentials to apple-app-site-association json file
{
    "applinks": {
        "apps": [],
        "details": {
            "9JA89QQLNQ.com.apple.wwdc": {
                "paths":[ "/wwdc/news/,
                        "/videos/wwdc/2015/*"] 
            }
        }
    }

    "webcredentials" : {
        "apps" : [ "a1234567".com.example.AppName"]
    }
}
  • code to retrieve the password
SecRequestSharedWebCredential(nil, nil) { cfcredentials, error in 
    //to check if there are any existing credentials for login
    // if it does , access the user name and password from cfcredentials and login (call ui in main queue)
    // if it does not, show login ui(call ui in main queue)

};
  • update saved credentials
    SecAddSharedWebCredentials("example.com", userName, password) {
    error in ...
    }
    
  • Generate secure password.
    let password:String = SecCreateSharedWebCredentialPassword().takeRetainedValue() as String
    //print it or something else.
    

Related session : Your app, Your website and safari