Skip to content
Supplement the Facebook ios sdk with Blocks & NSOperation goodness
Find file
Pull request Compare This branch is even with dmojdehi:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.



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)


    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 for more
                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.