I started to use Facebook SDK for iOS and i'm a little bit confused,
I'm seeing this little piece of code that shows how we can perform a batch request however having a completion handler per request is absurd for me. how can you make a completion handler per request when you make a single batch request ? maybe i didn't get the concept ? there is for sure an explanation for this but i don't see it right now
if ([[FBSDKAccessToken currentAccessToken] hasGranted:@"user_likes"]) {
FBSDKGraphRequest *requestMe = [[FBSDKGraphRequest alloc]
initWithGraphPath:@"me" parameters:nil];
FBSDKGraphRequest *requestLikes = [[FBSDKGraphRequest alloc]
initWithGraphPath:@"me/likes" parameters:nil];
FBSDKGraphRequestConnection *connection = [[FBSDKGraphRequestConnection alloc] init];
[connection addRequest:requestMe
completionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
//TODO: process me information
}];
[connection addRequest:requestLikes
completionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
//TODO: process like information
}];
[connection start];
}
If it is the only way to do it how can i know when all my requests have been performed ?
I created an FBBatchHandler class to automatically combine results and return a single completion handler to the caller. Source and example usage below. It's currently designed specifically for retrieving events (i.e. the final result is an NSArray of events), but it should be easily to repurpose it for other tasks. Let me know if this works for you.