简体   繁体   中英

iOS Facebook SDK batch requests, single completion block

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM