我正在使用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」內部檢索結果以便稍後(外部)使用它們?什麼樣的容器能幫助我?