-2

I have 4 web services. I want to call these 4 services at a time. How can i call multiple web services at a time? Can you suggest any tutorial for regarding this? Thanks in advance.

vishnu
  • 715
  • 9
  • 20

3 Answers3

1

You can use NSOperation queues or even Grand Central Dispatch(depends on your usage)

You must read multithreading link! and decide yourself.

aroragourav
  • 304
  • 3
  • 4
1
if you are not going to call four web services in the background then it will totally block your                 Application User Interface which results a worst experience to the user so it is better to use Apple Queue based technique to call web services in the background and populate your application interface accordingly.

you should use following  

//call service

//set url
dispatch_queue_t queue1 = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH,0);
//making asynch call
  dispatch_async(queue1,^{

//get your response
       dispatch_queue_t main = dispatch_get_main_queue();
dispatch_sync(main,^{

              //update your view interface with fetched data

           });
 });

Additionally when you create service method you have to pass url and payload (if needed) and set header etc so i think it will enhance application performance and interaction significantly .

Shobhakar Tiwari
  • 7,862
  • 4
  • 36
  • 71
1

You can use AFNetworking for multi request,https://github.com/AFNetworking/AFNetworking
why you want to do request in main thread, that will cause your UI waiting

Wayn Liu
  • 394
  • 3
  • 13