Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
iPhone API
Objective-C C
branch: master
Failed to load latest commit information.
Sources Added credentials as a separate class
README.textile Updates to the README


iPhone API for

Version 1.0 — Open Source (Apache License)

By Stefan Arentz, May 6th, 2010


This is a simple Objective-C API for the service. Although the API is capable of more tricks, this code currently only supports the shortening of URLs.

The API is fully asynchronous and can be easily embedded in any project. There are no dependencies on other libraries.


The code has been developed and tested for iPhone OS 3.0 and higher. It does not use anything specific to 3.0 so it should also work on 2.2.1.

Example Usage

 * Create a URLShortener instance. Configure it and then execute it. The instance is auto released. It will
 * be cleaned up automatically when one of the delegate methods has been called. If you want to keep it
 * around then simply retain it and keep it around in an instance variable.
 * Replace the login and key with your own.

- (void) demo
   URLShortener* shortener = [[URLShortener new] autorelease];
   if (shortener != nil) {
      shortener.delegate = self;
      shortener.login = @"LOGIN-REPLACE-ME";
      shortener.key = @"KEY-REPLACE-ME";
      shortener.url = [NSURL URLWithString: @""];
      [shortener execute];

 * URLShortener delegate method that will be called when the URL was succesfully shortened.

- (void) shortener: (URLShortener*) shortener didSucceedWithShortenedURL: (NSURL*) shortenedURL
   NSLog(@"shortener: %@ didSucceedWithShortenedURL: %@", self, [shortenedURL absoluteString]);

 * URLShortener delegate method that will be called when the service returned a non-200
 * status code to our request.

- (void) shortener: (URLShortener*) shortener didFailWithStatusCode: (int) statusCode
   NSLog(@"shortener: %@ didFailWithStatusCode: %d", self, statusCode);

 * URLShortener delegate method that will be called when a lower level error has occurred. Like
 * network timeouts or host lookup failures.

- (void) shortener: (URLShortener*) shortener didFailWithError: (NSError*) error
   NSLog(@"shortener: %@ didFailWithError: %d", self, [error localizedDescription]);
Something went wrong with that request. Please try again.