4

If I use NSURLConnection with sendAsynchronousRequest:queue:completionHandler:, do I need to take any particular precautions inside the completion handler? Specifically, is sending asynchronously directly via NSURLConnection the same/similar as using dispatch_async in that the completion block would need to come back to the main thread to interact with the UI?

For example: after using dispatch_async to interact (maybe the wrong word) with the UI, the app must use performSelectorOnMainThread.

Is that a consideration at all with sendAsynchronousRequest:queue:completionHandler:?

note: I have found similar questions, but not this specifically. eg, in Does NSURLConnection block the main thread? indiekiduk specifically states it is a new thread, albeit an internal one--I think that is flawed, since I thought it was just at the end of the run loop--but I am still learning and probably/possibly wrong.

Community
  • 1
  • 1
Madivad
  • 2,999
  • 7
  • 33
  • 60

2 Answers2

5

The documentation for NSURLConnection states for the queue parameter to sendAsynchronousRequest:queue:completionHandler:

queue
The operation queue to which the handler block is dispatched when the request completes or > failed.

The block will execute on whichever thread the passed in queue was set up on.

Jasarien
  • 58,279
  • 31
  • 157
  • 188
0

NSURLConnection sendAsync is scheduled on the RunLoop of the thread its on AFAIK so the block is called in the thread you start it

Daij-Djan
  • 49,552
  • 17
  • 113
  • 135