1

我有一个我想调用的朋友 ID 数组,然后存储返回的数据对象。

看起来像这样:

for (int i = 0; i < self.friendIDArray.count; i++){

            self.detailedRequest = [facebook requestWithGraphPath:[self.friendIDArray objectAtIndex:i] andDelegate:self];
        }

问题是我想我发送请求太频繁了,没有给 FB 机会正确返回数据?我怎样才能解决这个问题?谢谢

4

2 回答 2

1

这是您需要做的。这非常接近地模仿了您如何使用 NSURLConnection API 发出异步请求。

在你的 header/.h 文件中创建一个类属性(成员变量,无论你想怎么称呼它)

//header/.h file
int indexOfLastFriendLoaded;

在您的实现文件中:

- (void) loadFriend:(int) indexOfFriendToLoad {
    [facebook requestWithGraphPath:[self.friendIDArray objectAtIndex:indexOfFriendToLoad] andDelegate:self];
}

//this method is called when each facebook request finishes,
- (void)request:(FBRequest *)request didLoad:(id)result {
    //first do whatever you need to with "result" to save the loaded friend data

    //We make the next request from this method since we know the prior has already completed.
    if (indexOfLastFriendLoaded < [self.friendIDArray count]) {
        [self loadFriend:indexOfLastFriendLoaded];
        indexOfLastFriendLoaded++;
    }   
}

- (void) viewDidLoad {
    //initialize facebook object first

    indexOfLastFriendLoaded = 0;
    [self loadFriend:indexOfLastFriendLoaded];
}
于 2012-04-25T23:57:39.750 回答
0

requests api 建议您委派处理结果。

https://developers.facebook.com/docs/reference/iossdk/FBRequestDelegate/

于 2012-04-25T23:06:07.527 回答