我正在使用Facebook SDK for iOS。我可以用“NSLog”输出结果,但我不知道如何从外部检索FBSDKGraphRequest的结果值,因为它们位于完成块中。我需要这些值用于以后的操作。我试图把它们放在NSArray或NSMutableArray中,但无法做到。如何检索“FBSDKGraphRequest”的结果以便在外部使用?
的插图中的代码下面给出:
__block NSMutableArray *results;
__block NSArray *obj;
if ([[FBSDKAccessToken currentAccessToken] hasGranted:@"user_groups"]) {
NSLog(@"user_groups permission is granted!");
FBSDKGraphRequest *fgr = [[[FBSDKGraphRequest alloc]
initWithGraphPath:@"me/groups?fields=id"
parameters: nil
HTTPMethod:@"GET"]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!error) {
//here I can output the results
NSLog(@"User's groups:%@", [result[@"data"] valueForKey:@"id"]);
//trying to pass the values to NSMutableArray
obj = [result[@"data"] valueForKey:@"id"];
results = [NSMutableArray arrayWithArray:obj];
}
}];
}
...
NSLog(@"The size of the array of the results : %lu", [results count]);
这似乎是结果的NSMutableArray是空的,所以,我不能把结果存在的数据。如何从“FBSDKGraphRequest”内部检索结果以便稍后(外部)使用它们?什么样的容器能帮助我?