Slide 1

Slide 1 text

URL Schemes - Redux Jason Kneen Wednesday, 25 September 13

Slide 2

Slide 2 text

"CPVUNF http://twitter/jasonkneen http://github.com/jasonkneen http://jasonified.com http://bouncingfish.com App Developer, Titanium “Titan” Wednesday, 25 September 13

Slide 3

Slide 3 text

• 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 Wednesday, 25 September 13

Slide 4

Slide 4 text

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! Wednesday, 25 September 13

Slide 5

Slide 5 text

Examples Wednesday, 25 September 13

Slide 6

Slide 6 text

Launch Center Wednesday, 25 September 13

Slide 7

Slide 7 text

Launch Center apps How it works • App detection via URL Schemes • Ability to add “Actions” • Dependent on URL Scheme list Wednesday, 25 September 13

Slide 8

Slide 8 text

Launch Center apps Apps and Actions Wednesday, 25 September 13

Slide 9

Slide 9 text

iTunes / AppStore Wednesday, 25 September 13

Slide 10

Slide 10 text

AppStore / iTunes Launching the native app from search results Wednesday, 25 September 13

Slide 11

Slide 11 text

AppStore / iTunes Launching the native app from search results Wednesday, 25 September 13

Slide 12

Slide 12 text

Google Maps Wednesday, 25 September 13

Slide 13

Slide 13 text

Google Maps Launching the native app for map links Web App Native App Wednesday, 25 September 13

Slide 14

Slide 14 text

YouTube Wednesday, 25 September 13

Slide 15

Slide 15 text

YouTube Launching YouTube videos in the native app Google Search Native App Wednesday, 25 September 13

Slide 16

Slide 16 text

Gmail Wednesday, 25 September 13

Slide 17

Slide 17 text

Examples iOS Gmail app, detecting other Google app installs Before Google Maps installation After Google Maps installation Wednesday, 25 September 13

Slide 18

Slide 18 text

Examples Gmail opening Chrome App Switch Wednesday, 25 September 13

Slide 19

Slide 19 text

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 Wednesday, 25 September 13

Slide 20

Slide 20 text

Launching apps with actions • tweetbot:///post?text=&callback_url= • tweetbot:///search?query=&callback_url= • tweetbot:///user_profile/?callback_url= Controlling Tweetbot on iOS tweetbot://jasonkneen/post?text=Hello! Wednesday, 25 September 13

Slide 21

Slide 21 text

Launching apps with actions Try it out without code tweetbot://something/post?text=Hello! http://handleopenurl.com/scheme/tweetbot Wednesday, 25 September 13

Slide 22

Slide 22 text

URL Scheme usages • App launching (Chrome, Maps, YouTube) • Cross-promote apps • Single Sign On • SMS based Push Notifications • Use specific features of other apps Wednesday, 25 September 13

Slide 23

Slide 23 text

Single sign-on apps Launch SSO Login Find related Apps Prompt to install Wednesday, 25 September 13

Slide 24

Slide 24 text

Single sign-on apps Launch sub app SSO exists? Launch SSO Auth Yes Wednesday, 25 September 13

Slide 25

Slide 25 text

Push notifications with SMS Wednesday, 25 September 13

Slide 26

Slide 26 text

Push notifications with SMS SMS Arrives Click URL Launch App Process URL Wednesday, 25 September 13

Slide 27

Slide 27 text

Other uses • White Label app in AppStore • Generate “Bookmark” with custom URL • Bookmark has custom Icon / Name • e.g salonapp://?salonID=1234&theme=dark • Also, testing feature branches, languages, launching into sub-apps (Container based apps). White Labeling Wednesday, 25 September 13

Slide 28

Slide 28 text

Sending binary data between apps Wednesday, 25 September 13

Slide 29

Slide 29 text

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 Wednesday, 25 September 13

Slide 30

Slide 30 text

Demo Wednesday, 25 September 13

Slide 31

Slide 31 text

• Select a photo in app 1 • Encode it, send to app 2 • Decode and display • Edit it in App 2 • Send the new image back Wednesday, 25 September 13

Slide 32

Slide 32 text

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) Wednesday, 25 September 13

Slide 33

Slide 33 text

Implementing URL Schemes Gotchas - Android • Apps are launched as separate instances • App stays in browser context • Use SingleTask mode • Use Intents for picking up app resume URLs Wednesday, 25 September 13

Slide 34

Slide 34 text

Where to publish? http://wiki.akosma.com/IPhone_URL_Schemes http://handleopenurl.com http://applookup.com Wednesday, 25 September 13

Slide 35

Slide 35 text

Where to publish? Wednesday, 25 September 13

Slide 36

Slide 36 text

Detecting and launching apps on iOS                          if  (Ti.Platform.canOpenUrl(“tweetbot://”);{             //  do  stuff   Ti.Platform.openUrl(“tweetbot://default/post?text=Hello!”); } Wednesday, 25 September 13

Slide 37

Slide 37 text

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);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); Wednesday, 25 September 13

Slide 38

Slide 38 text

Register a URL Scheme for an App In iOS using info.plist Wednesday, 25 September 13

Slide 39

Slide 39 text

Register a URL Scheme for an App In Android TiApp.xml :- Wednesday, 25 September 13

Slide 40

Slide 40 text

Register a URL Scheme for an App In both iOS and Android within TiApp.xml Wednesday, 25 September 13

Slide 41

Slide 41 text

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 Wednesday, 25 September 13

Slide 42

Slide 42 text

Add handling code to parse URLs In Android (inc. for SingleTask mode) var  activity  =  Ti.Android.currentActivity;   var  processIntentURL  =  function(intent)  {     if  (intent.getData())  {       Ti.API.info("Android  URL  data:  "  +  intent.getData());       checkImportDetails(intent.getData());     }  else  {       Alloy.Globals.UI.openController('tutorial');     }   };   processIntentURL(activity.getIntent());  //  gets  the  first  load   activity.addEventListener("newintent",  function(e)  {                processIntentURL(e.intent);  //  gets  the  switch  back        });                                 http://tinyurl.com/urlschemecode Wednesday, 25 September 13

Slide 43

Slide 43 text

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 Wednesday, 25 September 13

Slide 44

Slide 44 text

URL Scheme compatibility issues • URL Schemes won’t work off device (mostly) • Not recognized by some apps / services e.g TinyURL • Solution: Use a hosted redirect script Wednesday, 25 September 13

Slide 45

Slide 45 text

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 Wednesday, 25 September 13

Slide 46

Slide 46 text

Using a redirect script http://www.foo.com/redirect.html? action=post&data=Hello redirect.html Check for App Launch App Fallback Wednesday, 25 September 13

Slide 47

Slide 47 text

Creating a redirect script Wednesday, 25 September 13

Slide 48

Slide 48 text

or use a URL Scheme Generator @joshj - Josh Jenson http://appurl.io/ • Creates a hosted link • Use it in emails, web, twitter etc • Fallback to AppStore / Other URL Wednesday, 25 September 13

Slide 49

Slide 49 text

or use a URL Scheme Generator http://appurl.io/ Wednesday, 25 September 13

Slide 50

Slide 50 text

Summary • Direct cross-platform, inter-app communication • Growing support from developers • Resources available to find out Schemes / Actions • Shorten, handle fallback, desktop access • You can send more than text! Wednesday, 25 September 13

Slide 51

Slide 51 text

Resources • https://gist.github.com/jasonkneen/5736738 • http://fokkezb.nl/2013/08/26/url-schemes-for-ios- and-android-1/ • http://fokkezb.nl/2013/09/20/url-schemes-for-ios- and-android-2/ Wednesday, 25 September 13

Slide 52

Slide 52 text

Thank you! Wednesday, 25 September 13