Skip to content
Block based SDK for iOS and Mac OS X
Objective-C Ruby
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

LastFm - block based SDK for iOS and Mac OS X

Loosely based on LastFMService from the official iPhone app, but non-blocking, more readable, much easier to use (and to extend) and with less dependencies.


  • Block based for easier usage
  • Only one dependency (KissXML)
  • Returns values in the correct data type (NSDate, NSURL, NSNumber, etc)
  • Actively developed and maintained (note: at the moment backwards-incompatible changes are to be expected)


// Set the session info
[LastFm sharedInstance].apiKey = @"xxx";
[LastFm sharedInstance].apiSecret = @"xxx";
[LastFm sharedInstance].session = session;
[LastFm sharedInstance].username = username;

// Get artist info
[[LastFm sharedInstance] getInfoForArtist:@"Pink Floyd" successHandler:^(NSDictionary *result) {
    NSLog(@"result: %@", result);
} failureHandler:^(NSError *error) {
    NSLog(@"error: %@", error);

// Get images for an artist
[[LastFm sharedInstance] getImagesForArtist:@"Cher" successHandler:^(NSArray *result) {
    NSLog(@"result: %@", result);
} failureHandler:^(NSError *error) {
    NSLog(@"error: %@", error);

// Scrobble a track
[[LastFm sharedInstance] sendScrobbledTrack:@"Wish You Were Here" byArtist:@"Pink Floyd" onAlbum:@"Wish You Were Here" withDuration:534 atTimestamp:(int)[[NSDate date] timeIntervalSince1970] successHandler:^(NSDictionary *result) {
    NSLog(@"result: %@", result);
} failureHandler:^(NSError *error) {
    NSLog(@"error: %@", error);

Save the username and session you get with getSessionForUser:password:successHandler:failureHandler: somewhere, for example in NSUserDefaults, and on app start up set it back on [LastFm sharedInstance].username and [LastFm sharedInstance].session.

See the included iOS project for examples on login, logout, getting artist info and more.


You can install LastFm with CocoaPods. You can also get the code and drag the LastFm subfolder into your Xcode project.


  • LastFm is built using ARC and modern Objective-C syntax. You will need Xcode 4.4 or higher to use it in your project.
  • You will need your own API key by registering at
  • KissXML


If you want all GET requests to be cached as aggressively as possible, install SDURLCache (or steipete's ARC fork). Then, add the following code to your app delegate's application:didFinishLaunchingWithOptions: method:

SDURLCache *URLCache = [[SDURLCache alloc] initWithMemoryCapacity:10 * 1024 * 1024
                                                     diskCapacity:50 * 1024 * 1024
                                                         diskPath:[SDURLCache defaultCachePath]];
[NSURLCache setSharedURLCache:URLCache];

Issues and questions

Have a bug? Please create an issue on GitHub!


LastFm is available under the MIT license. See the LICENSE file for more info.

Something went wrong with that request. Please try again.