There has been growing interest among the Titanium and Titan-community for the endless possibilities of URL schemes in iOS. This blog will try to give an overview, hoping to spark some new ideas.
NOTE: This post is outdated. There have been lots of issues and changes related to opening apps via intents and responding to URL schemes. See TIMOB-20490 for more information.
Android Intents
One of the major advantages of Android over iOS is its support for intents. This allows for profound inter-app communication. An app could for example start an intent requesting for a route to be planned. Any app like Google Maps, TomTom or other kind of navigation app can then offer it’s services. The user will be able to choose what app should perform the action and after the action has been performed, he will be returned to the app he was in, possibly providing that app with the result of the action, let’s say the route-length.
URL Schemes
In iOS there is no such thing as intents. Apps cán register to be considered when a user wants to open a certain kind of file (e.g. an image attached to an email), but this is very limited compared to Intents. The other thing apps register for are URL Schemes. Like Safari responds to http://
URLs, an app can register to respond to myapp://
or any other scheme(s). The good thing about URL Schemes is that they work not just on iOS, but also on Android, Mac, Windows and many OSes. But of course only if you have an app for that ;)
Underestimated
URL schemes have long been underestimated. The primary usage has been to open apps straight from an e-mail or web-page. But these URLs can also be opened directly from another app and apps can even ask iOS if the URL Scheme they want to open is registered for. And like any URL, it can contain a path and query string holding information for the opened app to process. For example, twitter://post?message=hello will open Twitter and show the dialog to post a new tweet saying hello.
Sending AND receiving data
When Jason Kneen was in Amsterdam for the Dutch Mobile Conference we both spook at, he also gave a talk at our Amsterdam Titanium meetup. Subject for that night: URL Schemes. After his talk we discussed in what more ways URL Schemes could be used. Jason came up with the idea that an URL can also contain base64 encoded binary data. A simple test I did showed that contrary to desktops, where an URL is limited to 2000 characters, there appears to be no such limit in iOS.. at all!
In the next days Jason quickly put together 2 apps that were able to exchange binary data. While iOS Schemes are only one-way, nothing stops you to add the URL Scheme of the first app as an argument to the URL Scheme of the second app, so that when it is done, it can return the user to the first app.
Put all this together and URL Schemes can do already much of what Android Intents can!
Thinking about possibilities
Last weekend Jason did another – updated – talk on URL Schemes at TiConf Baltimore, showing the 2 demo apps. I hope the talk and the following list of ideas will spark some new innovative apps!
- Prompt the user to download an app he hasn’t installed yet. You should always test if an URL Scheme you require is supported, but you can also more actively use this to promote apps.
- Open an item viewed on a webpage in it’s app by simply calling the corresponding URL Scheme. If the user doesn’t have the app installed, he’ll simply stay on the page (or you can prompt to install).
- Have app B return to app A by passing A’s URL Scheme (encoded) when opening B.
appB://?someArg=someVal&callback=appA://
- Send any data – text or base64 encoded file/image – to another app for editing. For example:
- Translate a text.
- Apply a nice filter to an image.
- Plan a route, returning the travel time.
- Share a text and/or image via some service, returning the URL.
- Upload a file to DropBox or Flickr, returning the URL.
- Get an URL shortened.
- Support SSO by opening app B and then pass a token when returning to A.
appB://authenticate&callback=app://authenicated?token=:token
appA://authenticated?token=1a2b3c - Style app B by passing colors and images from app A.
appB://theme?color=red&image=data:image/png;base64,iVBORw0KG...
- Unlock hidden (debug) parts of an app by opening the app using a specific URL.
app://?cmd=debugMode
app://?cmd=resetData
app://?cmd=sendLogs
app://?easterEgg=bunny - Request a payment to be done in app B and return a receipt to app A so it can do a background verification.
- Create a AddThis-like app that other apps can call, passing whatever they want to share. The user can then share it using hundreds of services, after which the calling app gets returned the URL of the shared status
- Create a intent-hub-app to wich other apps can register their URL Schemes for specific generalized actions.
hub://register?service=routing&callback=appB://route&to=:from
Calling a action from appA, via the hub to appB and back:
hub://request&service=routing&destination=New+York&calback=appA://?distance=:km
appB://route?to=New+York&action=1a2b3c
hub://respond?action=1a2b3c&distance=6000&otherInfo..
appA://?distance=6000
I’m sure there are many other things you can think of. Let me know on Twitter and I’ll add them to the list.
Flipping a coin
The main remaining drawback from URL Schemes compared to Android is that – apart from the intent-hub idea – app A has to know the URL Scheme of app B. iOS does allow for multiple apps to register to the same URL Scheme, but instead of letting user pick what app to use, Apple seems to just throw flip a coin :(
One more thing
One final thing I’ve playing with is combining URL Schemes with a hack to create custom iOS Springboard URL Scheme bookmarks. The only way to create such a bookmark is from Safari, where you can add the current webpage you’re viewing to the springboard. And the moment you enter an URL Scheme in it’s location bar, either the registered app will open or Safari will display an error. You will not be able to bookmark it.
But by combining Safari’s support for the data URI scheme, the web-app-capable meta tag and a simple JavaScript to detect if the page was opened a a full-screen web-app, you can trick Safari and bookmark a data URI encoded web-page that immediately calls a given URL Scheme.
The result allows you to add custom shortcuts to your iOS Springboard that directly link to an action of a specific app. For example, a shortcut to directly open the compose-dialog of the Twitter or Buffer app. Tweeting is now just 1 tap away!
Try it yourself by opening the following page on your iPhone/iPad:
http://dev.fokkezb.nl/shortcutter/
Check the code on GitHub:
https://gist.github.com/FokkeZB/5899387