如何制作API请求队列?所以我有一些功能:
...
- (void) getUserBasicInfo:(NSString *)stringWithContestOfId;
- (void) getMyFriends;
- (void) getMyEducation;
...
我想创建一个调用所有这些函数的函数。如何暂停直到第一个功能结束?我试着做这样的事情:
...
[currentUser getMyCurentCity];
while ([currentUser getFlag] != TRUE) {
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
}
[currentUser getMyCurentCity];
...
getFlag - 返回success-flag的函数,在以下情况下变为true:
- (void)request:(FBRequest *) request didReceiveResponse:(NSURLResponse *)response{
flag = TRUE;
NSLog(@"I have some information");
}
但最后当我使用这种方法时,只有一个成功请求。你有更多的想法如何做到这一点?这样做是完美的:NSOperationQueue。
答案 0 :(得分:0)
谢谢大家......
[currentUser getMyCurentCity];
while ([currentUser getFlag] != TRUE) {
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
}
[currentUser setFlagFalse];
[currentUser getUserBasicInfo:@"me"];
while ([currentUser getFlag] != TRUE) {
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
}
[currentUser setFlagFalse];