Cross-platform app links

Here are some notes after the recent research into deep linking into the apps. The goal was to launch the app on clicks on links in email. Traditionally, we were using a custom scheme to register the app as a handler for, but this didn't work quite well. So notes:

  • Don't use custom schemes. Links with custom schemes are no longer clickable in SMS, Chrome and Gmail on Android.
  • Use http / https schemes with your app domains. If your domains have "well-known" asset link files, your app is offered as the default handler. (Verification pending)

Quick start -- Android

  • Register intent-filter for your activity. Here we tell that this app can handle HTTP and HTTPS links to my.domain.com with paths starting with /app.
<android>  
  <manifest>
    <application>
      <activity ...>
        <intent-filter>
          <action android:name="android.intent.action.MAIN"/>
          <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
        <intent-filter>
          <action android:name="android.intent.action.VIEW"/>
          <category android:name="android.intent.category.DEFAULT"/>
          <category android:name="android.intent.category.BROWSABLE"/>
          <data android:scheme="https" />
          <data android:scheme="http" />
          <data android:host="my.domain.com" />
          <data android:pathPrefix="/app"/>
        </intent-filter>
      </activity>
    </application>
  </manifest>
</android>  
  • Put the app links verification file to the web server at my.domain.com/.well-known/assetlinks.json. This is only necessary if you want your app offered for that domain name links handling by default. If you can live with it just being offered along with Chrome or other browsers, that's fine to leave it out.
{ relation: [ "delegate_permission/common.handle_all_urls" ],
  target: {
    namespace: "android_app",
    package_name: "com.noizeramp.myapp",
    sha256_cert_fingerprints: [
      "14:6D:E9:83:C5:73:06:50:D8:EE:B9:95:2F:34:FC:64:16:A0:83:42:E6:1D:BE:A8:8A:04:96:B2:3F:CF:44:E5"
    ] }
}

You get fingerprint from $ keytool -list -v -keystore my-release-key.keystore

  • Add in-app handling of the event (Titanium version).
Ti.App.Android.launchIntent.getData()  

Quick start -- iOS

  • Register entitlements. Put the details into the MyApp.entitlements file:
<?xml version="1.0" encoding="UTF-8"?>  
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">  
<plist version="1.0">  
<dict>  
  <key>com.apple.developer.associated-domains</key>
  <array>
    <string>applinks:my.domain.com</string>
  </array>
</dict>  
</plist>  
  • Put the app links verification file to the web server. Here we tell that we allow the app with this appID to handle paths starting with /app on this domain. The app links verification file should be placed at my.domain.com/apple-app-site-association or my.domain.com/.well-known/apple-app-site-association.
applinks: {  
  apps: [],
  details: [
    { appID: "675aasd9f8.com.noizeramp.myapp",
      paths: [ "/app/*" ] }
  ]
}
  • Add in-app handling (Titanium version).
if (OS_IOS) {  
  Ti.App.iOS.addEventListener('continueactivity', function(e){
    // This is important hack for 5.2.x (until 5.4.0). This createUserActivity
    // call that is never exectured is needed for the compiler to know we are
    // interested in continueactivity event.
    if (e.activityType === "never-executed") {
      Ti.App.iOS.createUserActivity();
    }

    if (e.activityType === "NSUserActivityTypeBrowsingWeb"){
      onOpen(e.webpageURL);
    }
  });
}

Links of interest

comments powered by Disqus