How do I use AFNetworking with multiple requests?
I have multiple requests at the same time, I want to deal with it until they are fulfilled. Here are the requests:
[self getProfileData];
[self checkNewSystemMessage];
[self checkChatMessage];
As getProfileData
it looks like this:
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];
}];
and others are the same. I want to do something when it's over. The only way I thought was to request them one by one. Obviously, this is a stupid idea. So how can I find out the end time?
+3
source to share
2 answers
I am trying to figure this out too, but now I am successfully working on checking the number of operations inside an AFHTTPRequestOperationManager
OperationQueue inside the success of a block
[manager GET:URL_ADDRESS(portNumber,@"JsonEntryManager") parameters:dic success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"%@",responseObject);
if ([weakSelf.manager.operationQueue operationCount] == 0) {
//Do something here when all the operations are done.
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
[self performSelector:@selector(getProfileData) withObject:nil afterDelay:REQUEST_AGAIN_TIME];
}];
0
source to share