gpt4 book ai didi

afnetworking - 如何将 AFNetworking 用于多请求?

转载 作者:行者123 更新时间:2023-12-02 04:51:41 26 4
gpt4 key购买 nike

我同时有一些请求,我想处理直到全部完成。以下是要求:

[self getProfileData];
[self checkNewSystemMessage];
[self checkChatMessage];

getProfileData 中它看起来像:

AFHTTPRequestOperationManager* manager = [AFHTTPRequestOperationManager manager];
manager.requestSerializer.timeoutInterval = TIMEOUT_INTERVAL;
NSString * portNumber = [[NSUserDefaults standardUserDefaults] objectForKey:@"portNumber"];

[manager GET:URL_ADDRESS(portNumber,@"JsonEntryManager") parameters:dic success:^(AFHTTPRequestOperation *operation, id responseObject) {

NSLog(@"%@",responseObject);
//Do something...
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
[self performSelector:@selector(getProfileData) withObject:nil afterDelay:REQUEST_AGAIN_TIME];
}];

其他同理。我想在他们都完成后做点什么。我认为唯一的方法是一个一个地请求它们。显然这是一个愚蠢的想法。那么我怎么知道结束时间呢?

最佳答案

在开始任何请求之前初始化计数器:

int counter = 0;

在每个请求的成功 block 中,做

counter++;
if(counter==3)
{
//Do what you need to do when all the request is completed.
//Make some method for this.
}

关于afnetworking - 如何将 AFNetworking 用于多请求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27518030/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com