I use this AFNetworking method to start multiple requests at once:
- (void)enqueueBatchOfHTTPRequestOperations:(NSArray *)operations
progressBlock:(void (^)(NSUInteger numberOfCompletedOperations, NSUInteger totalNumberOfOperations))progressBlock
completionBlock:(void (^)(NSArray *operations))completionBlock
One of them is a AFJSONRequestOperation
. The problem is that the success-block of this JSON operation is executed after the completion-block of the batch. The reason is: AFJSONRequestOperation
has an internal dispatch queue for JSON processing. So the JSON data is still in processing while the completion block is called.
Question: How can execute code in the completion block after the success block of the JSON operation has been called?
I tried to dispatch a code block on the main queue but that didn't help.
If it's possible, the simplest solution might be just to move your processing code from the success block of each operation to the completion block of the whole batch.
You have the NSArray *operations
available in the completion block, you can iterate through the operations and look for:
for(AFHTTPRequestOperation *operation in operations){
if(operation.response.statusCode == 200){
//Do something with the response
}else{
//Handle the failure
}
}
You also have the url address for each operation available through the operation.request.URL
property if you need to preform different actions
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With