Launching the Bitly iPhone App (via X-Callback-Url)

The Bitly iPhone app supports the X-Callback-Url scheme via bitly://. This feature is available in Bitly for iPhone versions 1.3.1 and higher. Launching the Bitly for iPhone app can be done by calling:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"bitly://"]];

Determining if a user has the Bitly for iPhone app on their device

iOS provides developers one way to detect whether or not an application exists on a given user's device.

[[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"bitly://"]];

Which returns YES if the Bitly for iPhone app is on the user's device, NO otherwise.

Shortening a Link

Going beyond simply launching the Bitly for iPhone app, it is our goal to support developers wanting to work with the Bitly ecosystem on mobile.

Right now the Bitly iPhone app cross launching scheme only supports one action, creating links (this may change in the future). This will generate a Bitlink (bit.ly/something) from the URL you provide.

x-callback-url/shorten

Many Bitly users choose to store their saved links (sometimes called Bitlinks) for later. You can add URLs from your app to a user's Bitly account by calling:

bitly://x-callback-url/shorten?url=bitly.com

Bitly for iPhone will handle adding the passed url parameter (in this case, bitly.com) to the user's saved Bitlink list, provided he/she is already logged in. The url parameter should be URL encoded, which can be done in Objective-C by calling:

[url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

Returning the link

With the addition of a x-success parameter, you can specify a URL to call once a Bitlink has been successfully created, and the user chooses to dismiss the Add Bitlink view in the Bitly app.

bitly://x-callback-url/shorten?url=bitly.com&x-success=yourapp://action

Bitly will call:

yourapp://action?url=<RETURNED BITLY URL>

Errors and Cancelling

The Bitly for iPhone app also supports the x-cancel and x-error parameters, if you want the app to return to your app if the user cancels the shortening process, or an error is generated. At this point neither parameter, when executed, will return any additional information.

A final Bitly call might look something like:

bitly://x-callback-url/shorten?url=bitly.com&x-success=yourapp://action&x-cancel=yourapp://bitlycancel&x-error=yourapp://bitlyerror