The iOS Batch Request Page only shows how to execute multiple requests simultaneously and handle their outputs separately. However, I want to make 3 Facebook batch requests simultaneously, and then receive the results of all three in one completion block once all three have completed, so I can aggregate and sort them. Is this possible?
All help is greatly appreciated and I always accept an answer!
This method worked for me. Here's an example of how to do it requesting the user's info, and the user's friends that use your app. This will return to a single block, and you can parse the result and handle everything at once:
NSArray *requests = @[@{@"method":@"GET",
@"relative_url":@"me"},
@{@"method":@"GET",
@"relative_url":@"me/friends"}];
NSError *encodingError;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:requests options:0 error:&encodingError];
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
NSDictionary *params = @{@"batch":jsonString};
[FBRequestConnection startWithGraphPath:@""
parameters:params
HTTPMethod:@"POST"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (error) {
NSLog([error description], nil);
}
else {
NSLog(@"Return Data: %@", [result description]);
}
}];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With