Iphone 在iOS SDK中发出请求时,循环速度过快
我有一个朋友ID数组,我想调用它,然后存储返回的数据对象 看起来像这样:Iphone 在iOS SDK中发出请求时,循环速度过快,iphone,ios,xcode,facebook-graph-api,Iphone,Ios,Xcode,Facebook Graph Api,我有一个朋友ID数组,我想调用它,然后存储返回的数据对象 看起来像这样: for (int i = 0; i < self.friendIDArray.count; i++){ self.detailedRequest = [facebook requestWithGraphPath:[self.friendIDArray objectAtIndex:i] andDelegate:self]; } for(int i=0;i
for (int i = 0; i < self.friendIDArray.count; i++){
self.detailedRequest = [facebook requestWithGraphPath:[self.friendIDArray objectAtIndex:i] andDelegate:self];
}
for(int i=0;i
问题是我想我发送请求的频率太高了,没有给FB一个正确返回数据的机会?我怎样才能解决这个问题?谢谢请求api建议您委派一名代表来处理结果
请求api建议您委派一名代表来处理结果
以下是您需要做的事情。这与使用NSURLConnection API发出异步请求的方式非常相似 在header/.h文件中创建一个类属性(成员变量,不管您想叫它什么) 在您的实现文件中:
- (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];
}
-(void)loadFriend:(int)indexOfFriendToLoad{
[facebook requestWithGraphPath:[self.friendIDArray objectAtIndex:indexOfFriendToLoad]和delegate:self];
}
//此方法在每个facebook请求完成时调用,
-(void)请求:(FBRequest*)请求加载:(id)结果{
//首先,使用“result”来保存加载的好友数据
//我们从这个方法发出下一个请求,因为我们知道先前的请求已经完成。
if(indexOfLastFriendLoaded<[self.friendIDArray计数]){
[自加载好友:IndexOflastFriendload];
IndexOflastFriendload++;
}
}
-(无效)viewDidLoad{
//首先初始化facebook对象
IndexOflastFriendload=0;
[自加载好友:IndexOflastFriendload];
}
以下是您需要做的事情。这与使用NSURLConnection API发出异步请求的方式非常相似
在header/.h文件中创建一个类属性(成员变量,不管您想叫它什么)
在您的实现文件中:
- (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];
}
-(void)loadFriend:(int)indexOfFriendToLoad{
[facebook requestWithGraphPath:[self.friendIDArray objectAtIndex:indexOfFriendToLoad]和delegate:self];
}
//此方法在每个facebook请求完成时调用,
-(void)请求:(FBRequest*)请求加载:(id)结果{
//首先,使用“result”来保存加载的好友数据
//我们从这个方法发出下一个请求,因为我们知道先前的请求已经完成。
if(indexOfLastFriendLoaded<[self.friendIDArray计数]){
[自加载好友:IndexOflastFriendload];
IndexOflastFriendload++;
}
}
-(无效)viewDidLoad{
//首先初始化facebook对象
IndexOflastFriendload=0;
[自加载好友:IndexOflastFriendload];
}
是的,我使用didLoad方法,但它最后只执行一次。我想是因为我的循环发送请求太快了,干扰了响应?试一下这样的方法,只要你不在应用程序中,我就使用didLoad方法,但它最后只执行一次。我想是因为我的循环发送请求太快,干扰了响应?只要你不在应用程序代理中,就可以尝试这样的方法