Titanium and URL Schemes

Titanium and URL Schemes

Talk from TiConf US where I talk about implementing URL Schemes in your apps to allow two-way, inter-app communication and transferring of data and binary files.

088e93df631d5c679b107b855b4daa48?s=128

Jason Kneen

June 29, 2013
Tweet

Transcript

  1. URL Schemes Jason Kneen Saturday, 29 June 13

  2. URL Schemes Jason Kneen Saturday, 29 June 13

  3. "CPVUNF http://twitter/jasonkneen http://github.com/jasonkneen http://jasonified.com http://bouncingfish.com App Developer, Titanium “Titan” Saturday,

    29 June 13
  4. What is a URL Scheme? or "URI Schemes" if you

    like Saturday, 29 June 13
  5. What is a URL Scheme? "Top level of the uniform

    resource locator naming structure" or "URI Schemes" if you like Saturday, 29 June 13
  6. What is a URL Scheme? "Top level of the uniform

    resource locator naming structure" or "URI Schemes" if you like Saturday, 29 June 13
  7. • https:// What is a URL Scheme? "Top level of

    the uniform resource locator naming structure" or "URI Schemes" if you like Saturday, 29 June 13
  8. • https:// • ftp:// What is a URL Scheme? "Top

    level of the uniform resource locator naming structure" or "URI Schemes" if you like Saturday, 29 June 13
  9. • https:// • ftp:// • mailto: What is a URL

    Scheme? "Top level of the uniform resource locator naming structure" or "URI Schemes" if you like Saturday, 29 June 13
  10. • https:// • ftp:// • mailto: • tel: What is

    a URL Scheme? "Top level of the uniform resource locator naming structure" or "URI Schemes" if you like Saturday, 29 June 13
  11. • https:// • ftp:// • mailto: • tel: • outlook://

    What is a URL Scheme? "Top level of the uniform resource locator naming structure" or "URI Schemes" if you like Saturday, 29 June 13
  12. What can we do with them? The same thing we

    do every night, Pinky - try to take over the URL! Saturday, 29 June 13
  13. What can we do with them? • Detect Apps The

    same thing we do every night, Pinky - try to take over the URL! Saturday, 29 June 13
  14. What can we do with them? • Detect Apps •

    Launch / Resume Apps The same thing we do every night, Pinky - try to take over the URL! Saturday, 29 June 13
  15. What can we do with them? • Detect Apps •

    Launch / Resume Apps • Send commands/data to apps The same thing we do every night, Pinky - try to take over the URL! Saturday, 29 June 13
  16. What can we do with them? • Detect Apps •

    Launch / Resume Apps • Send commands/data to apps • Receive data/callbacks from apps The same thing we do every night, Pinky - try to take over the URL! Saturday, 29 June 13
  17. Examples Saturday, 29 June 13

  18. Launch Center Saturday, 29 June 13

  19. Launch Center apps How it works Saturday, 29 June 13

  20. Launch Center apps How it works • App detection via

    URL Schemes Saturday, 29 June 13
  21. Launch Center apps How it works • App detection via

    URL Schemes • Ability to add “Actions” Saturday, 29 June 13
  22. Launch Center apps How it works • App detection via

    URL Schemes • Ability to add “Actions” • Dependent on URL Scheme list Saturday, 29 June 13
  23. Launch Center apps Apps and Actions Saturday, 29 June 13

  24. Launch Center apps Apps and Actions Saturday, 29 June 13

  25. iTunes / AppStore Saturday, 29 June 13

  26. AppStore / iTunes Launching the native app from search results

    Saturday, 29 June 13
  27. AppStore / iTunes Launching the native app from search results

    Saturday, 29 June 13
  28. AppStore / iTunes Launching the native app from search results

    Saturday, 29 June 13
  29. Google Maps Saturday, 29 June 13

  30. Google Maps Launching the native app for map links Saturday,

    29 June 13
  31. Google Maps Launching the native app for map links Web

    App Saturday, 29 June 13
  32. Google Maps Launching the native app for map links Web

    App Saturday, 29 June 13
  33. Google Maps Launching the native app for map links Web

    App Native App Saturday, 29 June 13
  34. YouTube Saturday, 29 June 13

  35. YouTube Launching YouTube videos in the native app Saturday, 29

    June 13
  36. YouTube Launching YouTube videos in the native app Google Search

    Saturday, 29 June 13
  37. YouTube Launching YouTube videos in the native app Google Search

    Native App Saturday, 29 June 13
  38. Gmail Saturday, 29 June 13

  39. Examples iOS Gmail app, detecting other Google app installs Saturday,

    29 June 13
  40. Examples iOS Gmail app, detecting other Google app installs Before

    Google Maps installation Saturday, 29 June 13
  41. Examples iOS Gmail app, detecting other Google app installs Before

    Google Maps installation After Google Maps installation Saturday, 29 June 13
  42. Examples Gmail opening Chrome Saturday, 29 June 13

  43. Examples Gmail opening Chrome App Switch Saturday, 29 June 13

  44. Apps using URL Schemes • youtube:// • tweetbot:// • googlemaps://

    • twitter:// • bufferapp:// • linkedin:// • pinterest:// • googlegmail:// Enter into the browser to test • http://wiki.akosma.com/IPhone_URL_Schemes Useful links • http://canhandleUrl.com Saturday, 29 June 13
  45. Launching apps with actions Controlling Tweetbot on iOS Saturday, 29

    June 13
  46. Launching apps with actions • tweetbot://<screenname>/post?text=<text>&callback_url=<url> • tweetbot://<screenname>/search?query=<text>&callback_url=<url> • tweetbot://<screenname>/user_profile/<screenname>?callback_url=<url>

    Controlling Tweetbot on iOS Saturday, 29 June 13
  47. Launching apps with actions • tweetbot://<screenname>/post?text=<text>&callback_url=<url> • tweetbot://<screenname>/search?query=<text>&callback_url=<url> • tweetbot://<screenname>/user_profile/<screenname>?callback_url=<url>

    Controlling Tweetbot on iOS tweetbot://jasonkneen/post?text=Hello! Saturday, 29 June 13
  48. Launching apps with actions Try it out without code tweetbot://something/post?text=Hello!

    http://tinyurl.com/ticonfurl http://handleopenurl.com/scheme/tweetbot Saturday, 29 June 13
  49. Launching apps with actions Try it out without code tweetbot://something/post?text=Hello!

    http://tinyurl.com/ticonfurl http://handleopenurl.com/scheme/tweetbot Saturday, 29 June 13
  50. URL Scheme usages Saturday, 29 June 13

  51. URL Scheme usages • App launching (Chrome, Maps, YouTube) Saturday,

    29 June 13
  52. URL Scheme usages • App launching (Chrome, Maps, YouTube) •

    Cross-promote apps Saturday, 29 June 13
  53. URL Scheme usages • App launching (Chrome, Maps, YouTube) •

    Cross-promote apps • Single Sign On Saturday, 29 June 13
  54. URL Scheme usages • App launching (Chrome, Maps, YouTube) •

    Cross-promote apps • Single Sign On • SMS based Push Notifications Saturday, 29 June 13
  55. URL Scheme usages • App launching (Chrome, Maps, YouTube) •

    Cross-promote apps • Single Sign On • SMS based Push Notifications • Use specific features of other apps Saturday, 29 June 13
  56. Single sign-on apps Saturday, 29 June 13

  57. Single sign-on apps Launch SSO Saturday, 29 June 13

  58. Single sign-on apps Launch SSO Saturday, 29 June 13

  59. Single sign-on apps Launch SSO Login Saturday, 29 June 13

  60. Single sign-on apps Launch SSO Login Saturday, 29 June 13

  61. Single sign-on apps Launch SSO Login Find related Apps Saturday,

    29 June 13
  62. Single sign-on apps Launch SSO Login Find related Apps Saturday,

    29 June 13
  63. Single sign-on apps Launch SSO Login Find related Apps Prompt

    to install Saturday, 29 June 13
  64. Single sign-on apps Saturday, 29 June 13

  65. Single sign-on apps Launch sub app Saturday, 29 June 13

  66. Single sign-on apps Launch sub app Saturday, 29 June 13

  67. Single sign-on apps Launch sub app SSO exists? Saturday, 29

    June 13
  68. Single sign-on apps Launch sub app SSO exists? Saturday, 29

    June 13
  69. Single sign-on apps Launch sub app SSO exists? Yes Saturday,

    29 June 13
  70. Single sign-on apps Launch sub app SSO exists? Launch SSO

    Yes Saturday, 29 June 13
  71. Single sign-on apps Launch sub app SSO exists? Launch SSO

    Yes Saturday, 29 June 13
  72. Single sign-on apps Launch sub app SSO exists? Launch SSO

    Auth Yes Saturday, 29 June 13
  73. Single sign-on apps Launch sub app SSO exists? Launch SSO

    Auth Yes Saturday, 29 June 13
  74. Single sign-on apps Launch sub app SSO exists? Launch SSO

    Auth Yes Saturday, 29 June 13
  75. Push notifications with SMS Saturday, 29 June 13

  76. Push notifications with SMS Saturday, 29 June 13

  77. Push notifications with SMS SMS Arrives Saturday, 29 June 13

  78. Push notifications with SMS SMS Arrives Saturday, 29 June 13

  79. Push notifications with SMS SMS Arrives Click URL Saturday, 29

    June 13
  80. Push notifications with SMS SMS Arrives Click URL Saturday, 29

    June 13
  81. Push notifications with SMS SMS Arrives Click URL Launch App

    Saturday, 29 June 13
  82. Push notifications with SMS SMS Arrives Click URL Launch App

    Saturday, 29 June 13
  83. Push notifications with SMS SMS Arrives Click URL Launch App

    Process URL Saturday, 29 June 13
  84. Sending binary data between apps Saturday, 29 June 13

  85. Sharing data between apps Transferring binary files Saturday, 29 June

    13
  86. Sharing data between apps • Encode the file into base64

    Transferring binary files Saturday, 29 June 13
  87. Sharing data between apps • Encode the file into base64

    • Transfer it via URL Transferring binary files Saturday, 29 June 13
  88. Sharing data between apps • Encode the file into base64

    • Transfer it via URL • URL Decode on the other side Transferring binary files Saturday, 29 June 13
  89. Sharing data between apps • Encode the file into base64

    • Transfer it via URL • URL Decode on the other side • Decode from base64 Transferring binary files Saturday, 29 June 13
  90. Sharing data between apps • Encode the file into base64

    • Transfer it via URL • URL Decode on the other side • Decode from base64 • Do Stuff Transferring binary files Saturday, 29 June 13
  91. Demo Saturday, 29 June 13

  92. Implementing URL Schemes Adding to Titanium Apps Saturday, 29 June

    13
  93. Implementing URL Schemes Adding to Titanium Apps • Register a

    URL Scheme for an App Saturday, 29 June 13
  94. Implementing URL Schemes Adding to Titanium Apps • Register a

    URL Scheme for an App • Add events and handling code to read url Saturday, 29 June 13
  95. Implementing URL Schemes Adding to Titanium Apps • Register a

    URL Scheme for an App • Add events and handling code to read url • Add code to parse URLs Saturday, 29 June 13
  96. Implementing URL Schemes Adding to Titanium Apps • Register a

    URL Scheme for an App • Add events and handling code to read url • Add code to parse URLs • Add actions, responses, callbacks Saturday, 29 June 13
  97. Implementing URL Schemes Adding to Titanium Apps • Register a

    URL Scheme for an App • Add events and handling code to read url • Add code to parse URLs • Add actions, responses, callbacks • Let people know about it (if public) Saturday, 29 June 13
  98. Where to publish? http://wiki.akosma.com/IPhone_URL_Schemes http://handleopenurl.com http://applookup.com Saturday, 29 June 13

  99. Where to publish? Saturday, 29 June 13

  100. Detecting and launching apps on iOS        

                     if  (Ti.Platform.canOpenUrl(“tweetbot://”);{           //  do  stuff Ti.Platform.openUrl(“tweetbot://default/post? text=Hello!”);                } Saturday, 29 June 13
  101. Detecting and launching apps on Android var  myIntent  =  Ti.Android.createIntent({

                               action:  Ti.Android.ACTION_MAIN,                            packageName:  "com.mybundle.appname",                            className:  "com.mybundle.appname.appname",                            flags:  Ti.Android.FLAG_ACTIVITY_NEW_TASK, }); myIntent.addCategory(Ti.Android.CATEGORY_LAUNCHER); Ti.Android.currentActivity.startActivity(  myIntent  ); Saturday, 29 June 13
  102. Register a URL Scheme for an App In iOS using

    info.plist Saturday, 29 June 13
  103. Register a URL Scheme for an App In Android <android

    xmlns:android="http://schemas.android.com/apk/res/android"> <manifest android:versionCode="1" android:versionName="1.00"/> <activities> <activity url="app.js"> <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:host="" android:scheme="myscheme"/> </intent-filter> </activity> </activities> </android> TiApp.xml :- Saturday, 29 June 13
  104. Register a URL Scheme for an App In Android <android

    xmlns:android="http://schemas.android.com/apk/res/android"> <manifest android:versionCode="1" android:versionName="1.00"/> <activities> <activity url="app.js"> <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:host="" android:scheme="myscheme"/> </intent-filter> </activity> </activities> </android> TiApp.xml :- Saturday, 29 June 13
  105. Register a URL Scheme for an App In both iOS

    and Android within TiApp.xml Saturday, 29 June 13
  106. Add handling code to parse URLs In iOS, trap app

    start and resume events                          if  (Ti.App.getArguments().url)  {                                  urlToObject(Ti.App.getArguments().url);                } http://tinyurl.com/urlschemecode Saturday, 29 June 13
  107. Add handling code to parse URLs In Android var  activity

     =  Ti.Android.currentActivity; var  data  =  activity.getIntent().getData();                                if  (data)  {                    urlToObject(data);                } http://tinyurl.com/urlschemecode Saturday, 29 June 13
  108. Parsing the URLs In Android and iOS function  urlToObject(url)  {

    var  returnObj  =  {}; url  =  url.replace('URLSCHEME://?',  ''); var  params  =  url.split('&'); params.forEach(function(param)  {                                 var  keyAndValue  =  param.split('='); returnObj[keyAndValue[0]]  =  decodeURI(keyAndValue[1]); }); return  obj; } http://tinyurl.com/urlschemecode Saturday, 29 June 13
  109. URL Scheme compatibility issues Saturday, 29 June 13

  110. URL Scheme compatibility issues • URL Schemes on non-mobile devices

    Saturday, 29 June 13
  111. URL Scheme compatibility issues • URL Schemes on non-mobile devices

    • Not recognized by some apps / services Saturday, 29 June 13
  112. URL Scheme compatibility issues • URL Schemes on non-mobile devices

    • Not recognized by some apps / services • Use a redirect script Saturday, 29 June 13
  113. Using a redirect script Saturday, 29 June 13

  114. Using a redirect script • Allows you to detect apps,

    act accordingly Saturday, 29 June 13
  115. Using a redirect script • Allows you to detect apps,

    act accordingly • You can use services that don’t accept URL schemes Saturday, 29 June 13
  116. Using a redirect script • Allows you to detect apps,

    act accordingly • You can use services that don’t accept URL schemes • Allows checking, fallback URLs Saturday, 29 June 13
  117. Using a redirect script Saturday, 29 June 13

  118. Using a redirect script http://www.foo.com/redirect.html? action=post&data=Hello Saturday, 29 June 13

  119. Using a redirect script http://www.foo.com/redirect.html? action=post&data=Hello Saturday, 29 June 13

  120. Using a redirect script http://www.foo.com/redirect.html? action=post&data=Hello redirect.html Saturday, 29 June

    13
  121. Using a redirect script http://www.foo.com/redirect.html? action=post&data=Hello redirect.html Saturday, 29 June

    13
  122. Using a redirect script http://www.foo.com/redirect.html? action=post&data=Hello redirect.html Check for App

    Saturday, 29 June 13
  123. Using a redirect script http://www.foo.com/redirect.html? action=post&data=Hello redirect.html Check for App

    Saturday, 29 June 13
  124. Using a redirect script http://www.foo.com/redirect.html? action=post&data=Hello redirect.html Check for App

    Saturday, 29 June 13
  125. Using a redirect script http://www.foo.com/redirect.html? action=post&data=Hello redirect.html Check for App

    Fallback Saturday, 29 June 13
  126. Using a redirect script http://www.foo.com/redirect.html? action=post&data=Hello redirect.html Check for App

    Launch App Fallback Saturday, 29 June 13
  127. Creating a redirect script Saturday, 29 June 13

  128. Creating a redirect script Saturday, 29 June 13

  129. Summary Saturday, 29 June 13

  130. Summary • Direct cross-platform, inter-app communication Saturday, 29 June 13

  131. Summary • Direct cross-platform, inter-app communication • Growing support from

    developers Saturday, 29 June 13
  132. Summary • Direct cross-platform, inter-app communication • Growing support from

    developers • Resources available to find out Schemes / Actions Saturday, 29 June 13
  133. Summary • Direct cross-platform, inter-app communication • Growing support from

    developers • Resources available to find out Schemes / Actions • Shorten, handle failures, desktop access Saturday, 29 June 13
  134. Summary • Direct cross-platform, inter-app communication • Growing support from

    developers • Resources available to find out Schemes / Actions • Shorten, handle failures, desktop access • You can send more than text! Saturday, 29 June 13
  135. Thank you! Saturday, 29 June 13