Need alternative of NSURLConnection sendSynchronousRequest

888 views Asked by At

I want to do some task synchronously as :

[NSURLConnection sendSynchronousRequest:Request returningResponse:&response error:&error];

is deprecated what I can use in place of this.

2

There are 2 answers

17
Nilesh Patel On BEST ANSWER

Use dispatch_sync to perform synchronously tasks.

dispatch_sync(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{

      NSLog(@"Required task code.");
      dispatch_async(dispatch_get_main_queue(), ^{ 
      // Update UI in main thread. 
      // Add your UI Label Update code here..
     }); 
  });

Let me know if you need anymore help..

0
arwaz shaikh On

Using "NSURLSession-SynchronousTask" library produces me same results as NSURLConnection .