Handling Multiple API calls in same UIController class


Problem:
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.

Solution:
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:

Multiple-API-Calls-Handling

Comments

Popular posts from this blog

UITableView - Add or Remove Rows Dynamically (Objective C & Swift Source codes)

payUmoney Payment Gateway Integration in iOS App (Objective C)

Check Internet Connectivity Using AFNetworking 2.0