Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Supplement the Facebook ios sdk with Blocks & NSOperation goodness
Objective-C
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
FBRequestOperation.h
FBRequestOperation.m
Facebook+Blocks.h
Facebook+Blocks.m
LICENSE-MIT.txt
Readme.mdown

Readme.mdown

Facebook+Blocks

This is a simple wrapper to the Facebook iOS Library, providing a block- (and NSOperation-) based interface to instead of delegates the official sdk uses. Specifically, it provides: - extensions to the Facebook class to request resources using blocks for completetion (instead of delegates) - the resource request is encapsulated in FBRequestOperation, an NSOperation subclass

If you're already using the official sdk it's very easy to switch to these classes; the Facebook wrapper adds methods similar to the ones you're already using.

Advantages of NSOperations allow your code to: - enqueue multiple requests, with dependencies - for example, get the list of photos in an album, then load all the photos, and when all are complete update the UI - dispatch requests in parallel (quicker), or serially (cellular-data friendly)

Example:

    FBRequestOperation *infoReq = [mFacebookApi requestWithGraphPath:@"me" andCompletionHandler:^(FBRequestOperation *request, id jsonResponse, NSError *err) {

            // response for "me":
            // {
            //          "first_name" = Your;
            //          gender = male;
            //          id = 99999999999;
            //          "last_name" = Name;
            //          name = "Your Name";
            //          username = yourname;
            //          verified = 1;
            //          ...
            //  }
            // See http://developers.facebook.com/docs/reference/api/ for more
            if(!err)
            {
                NSString *userName = [jsonResponse objectForKey:@"name"];
            }

    }]; 
    [[NSOperationQueue mainQueue] addOperation:infoReq];

TODO: - Block the FBRequestOperation from completion until the provided completion block is also finished - currently any dependent operations may begin exexuting in parallel with your completion block - this makes it difficult to pass resulting data from one operation to the next - Create the FBRequest earlier - currently the request is created only when the FBRequestOperation begins - this makes it difficult to inspect or modify the parameters of the request

Something went wrong with that request. Please try again.