我有一个 friend ID 数组,我想调用它然后存储返回的数据对象。
看起来像这样:
for (int i = 0; i < self.friendIDArray.count; i++){
self.detailedRequest = [facebook requestWithGraphPath:[self.friendIDArray objectAtIndex:i] andDelegate:self];
}
问题是我想我发送请求的频率太高了,没有给 FB 机会正确返回数据?我怎样才能解决这个问题?谢谢
最佳答案
这是您需要做的。这非常类似于您使用 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];
}
关于iphone - 在 iOS SDK 中发出请求,循环飞得太快,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10324610/