-1

I need call two API at the same time in view controller.One API (API 1) called every 5 seconds.And other API(API 2) called at the same time . But It will take 1 minutes(Long time to get the response).

My issue is When i call API 2 of that time unable to get response of API 1. API 1 is waiting for complete API 2 Response , After that I got the response of API 1. I want API 1 response. API 1 is No need to wait for API 2 response.

How can i can implement the logic ? Thanks in advance.

Jamshed Alam
  • 12,424
  • 5
  • 26
  • 49
Jagan G
  • 13
  • 4

1 Answers1

1

Do you know https://github.com/AFNetworking/AFNetworking ? Get some example of this. Search on google.

Have a look on these:

  1. https://www.raywenderlich.com/59255/afnetworking-2-0-tutorial
  2. How to do GET request via AFNetworking?
  3. How to sign up through Rest API using AFNetworking 2.0?

If you don't want to use this, use dispatch_async.

Call 1 API:

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

 //api call 

 dispatch_async(dispatch_get_main_queue(), ^{

     //UI operations, when you receive data. 

 });

 });

Call API 2:

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

 //api call 

 dispatch_async(dispatch_get_main_queue(), ^{

     //UI operations, when you receive data. 

 });

 });

It won't hamper another process. Thanks!

Community
  • 1
  • 1
Jamshed Alam
  • 12,424
  • 5
  • 26
  • 49
  • Suggesting the use of a 3rd party Library is not the best/ideal answer. If you have a way to do it in Native swift then please update your answer – Anjan Biswas Nov 23 '17 at 18:11
  • You can not implement better something with your own try within short time than Afnetworking because it is developed by group of people. – Jamshed Alam Nov 24 '17 at 04:04