iOS Handling Multiple Asynchronous Requests: Send a Signal When All Requests Are Finished

yretuta picture yretuta · Sep 20, 2011 · Viewed 7.8k times · Source

So I am browsing over Stack Overflow for ways to handle asynchronous requests effectively. Right now I am using ASIHTTPRequest and my application consumes a REST API, in which a request to a single resource prompts me to request 5 or more additional resources (linked resources).

Right now I am doing all asynchronous request inside one huge method, there may be around 6 asynchronous request each with their setCompletionBlock and setFailBlock. If you have used ASIHTTPRequest, you must have an idea of how much repetitive code that will take.

Anyway, I seem to have found a solution to determine if all requests are finished with this answer: Multiple asynchronous URL requests

however, I don't know how to apply that answer in code ,as I have not used push notifications before and I have always used "self" as delegats and never other classes.

Any ideas how I can apply the answer to code or better yet, do you know of any other methods?

Thanks in advance!

Answer

Michael Frederick picture Michael Frederick · Sep 20, 2011

Put all the requests into an ASINetworkQueue: http://allseeing-i.com/ASIHTTPRequest/How-to-use#about_ASINetworkQueues.

ASINetworkQueue has a callback called "queueDidFinishSelector".