Skip to content
Facebook SDK for iOS
Pull request Compare This branch is even with evsukov89:continuations.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
sample
src
test/UnitTest
.gitignore
README.mdown

README.mdown

Facebook iOS SDK with blocks

This is an original iOS SDK converted to use Blocks instead of delegation. Functionality is pretty much the same with some small additions like correct method naming, upload/download progress callbacks in FBRequest, etc.

Some examples(taken from demo app):

login:

[_facebook authorizeWithPersmissions:_permissions completionHandler:^(FBAuthorizeResult result) {
    if (result == FBAuthorizeResultUserDidLogin) {
        [self.label setText:@"logged in"];
        _getUserInfoButton.hidden = NO;
        _getPublicInfoButton.hidden = NO;
        _publishButton.hidden = NO;
        _uploadPhotoButton.hidden = NO;
        _uploadPhotoProgressView.hidden = NO;
        _fbButton.isLoggedIn = YES;
        [_fbButton updateImage];            
    }
    else if (result == FBAuthorizeResultUserDidCanceled) {
        NSLog(@"did not login");
    }
}];

request to Graph API:

FBRequest *request = [self.facebook buildRequestWithGraphPath:@"me"];
[request performWithCompletionHandler:^(NSURLResponse* response, id result, NSError* error){
     NSLog(@"%s:%@ - %@ - %@",__PRETTY_FUNCTION__,response,result,error);
     if (error) {
         self.label.text = [error localizedDescription];
         return;
     }

     if ([result isKindOfClass:[NSArray class]]) {
         result = [result objectAtIndex:0];
     }

     self.label.text = [result objectForKey:@"name"];
}];

upload a photo:

UIImage *img  = ...

NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                               img, @"picture",nil];

FBRequest *request = [_facebook buildRequestWithGraphPath:@"me/photos" params:params httpMethod:@"POST"];

_uploadPhotoProgressView.progress = 0.0f;
request.uploadProgressHandler = ^(float progress){
    NSLog(@"%s:%f",__PRETTY_FUNCTION__,progress);
    _uploadPhotoProgressView.progress = progress;
};
[request performWithCompletionHandler:^(NSURLResponse* response, id result, NSError* error){
    NSLog(@"%s:%@ - %@ - %@",__PRETTY_FUNCTION__,response,result,error);
    if (error) {
        NSLog(@"%s:%@",__PRETTY_FUNCTION__,error);
        self.label.text = [error localizedDescription];
        return;
    }

    if ([result isKindOfClass:[NSArray class]]) {
        result = [result objectAtIndex:0];
    }

    if ([result objectForKey:@"owner"]) {
        [self.label setText:@"Photo upload Success"];
    } 

}];

TODO

  • more code refactoring. Currently it is mostly straight port from delegation. I also think that we can get rid of FBLoginDialog
  • update documentation and generate AppleDoc so we would be able to link it into Xcode documentation.
  • more examples
  • merge with official repository
Something went wrong with that request. Please try again.