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"];
}
}];
- 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