iOS Custom URL Schemes for Fun & Profit

February 11, 2013
Development iOS

I was talking to Aaron London last week and he turned me on to a use of custom URL schemes that I had not thought of. Custom URL schemes are a good way to track conversions from the lite version of an app to the full version and provide your customers with a way to transfer their data as well. The next version of Numerology Lite and Numerology will be taking advantage of this.

First, the lite app needs to create a custom URL scheme that the full version can invoke. Lets call it liteapp. Then when the full version launches it calls -UIApplication canOpenURL: passing it a URL that starts with the scheme liteapp. canOpenURL: will return true if the lite app is installed on the system. This also tells us that the customer previously had the lite version and they have purchased the full version.

Now, say we want to import the data from the lite version into the full version. The full app determines if the lite app exists (as above) and then invokes the URL, which might be something like liteapp://export. The lite app (in its application:openURL:sourceApplication:annotation: method recognizes the URL and proceeds to copy its data on to the pasteboard (see UIPasteboard).

Now the lite app needs a way to tell the full app that the data is on the pasteboard. So the full app  provides its own custom URL scheme. Lets call it fullapp. Once the lite version has put the data on the pasteboard, it invokes the URL full app://import, for example. The full app handles the URL in its own application:openURL:sourceApplication:annotation: method and gets the data from the pasteboard and imports it.

You may want to ask the user if they want to import before actually doing so. You can do this to be nice or to just let them know that your about to do something great for them. You can also thank them for upgrading.

You’ll also want to save a flag (probably in NSUserDefaults) to let you know if you’ve already gone through this lite to full data migration process and you don’t need to do it again.

The whole process is pretty simple to implement and your customers will really appreciate not having to re-enter their data. You’ll also be able to track lite to full conversions as well.