Monday, 13 August 2012

Handling Multiple API calls in same UIController class

I was facing problem in handling multiple API calls in same UIController class, as responses of all come into same delegate method named "requestFinished" and we have to use flags & if-else loops for handling each response.

1. In this code i have made 3 Asynchronous API calls in same UIController class.
2. On button action all 3 API web metods are called at once.
3. For handling each API i have made a separate NSObject class.
4. I am passing API urls from UIController class to their respective NSObject class.
5. When API is called, control is handled to its respective NSObject class.
6. Each NSObject class has its own delegate method named "requestFinished" to handle API response.
7. As API response is received control is again passed on to UIController class.
8. In this manner we can make Multiple Async API calls at once from same UIController class.

In some cases one API call depends on other API call response. In such situation just call First API and when the its response is passed on to UIController class from NSObject class, call the Second API at that point.

You can download code from here:


No comments:

Post a Comment