2011-11-08 84 views
0

如何製作API請求隊列?所以我有一些功能:Facebook Graph API請求隊列(iOS)

... 

- (void) getUserBasicInfo:(NSString *)stringWithContestOfId; 
- (void) getMyFriends; 
- (void) getMyEducation; 

... 

我想做一個函數,調用所有這些功能。如何暫停,直到第一個功能完成?我試圖做這樣的事情:

... 

[currentUser getMyCurentCity]; 
    while ([currentUser getFlag] != TRUE) { 
     [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]; 
}  

[currentUser getMyCurentCity]; 

... 

getFlag - 返回成功標誌的職能,這成爲真正:

- (void)request:(FBRequest *) request didReceiveResponse:(NSURLResponse *)response{ 
    flag = TRUE; 
    NSLog(@"I have some information"); 
} 

但是最後當我用這個方法存在的只有一種成功,請求許多。你有更多的想法如何做到這一點?這將是完美的,像:NSOperationQueue。

回答

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];