NSURLConnection and sendAsynchronousRequest: queue: completeHandler: - does the completion block execute in the main thread

If I use NSURLConnection with sendAsynchronousRequest:queue:completionHandler: do I need to take any special precautions inside the completion handler? In particular, it sends asynchronously directly through NSURLConnection the same / similar as when using dispatch_async , in that the termination block must return to the main thread to interact with the user interface?

For example: after using dispatch_async to interact (possibly with the wrong word) with the user interface, the application should use performSelectorOnMainThread .

Is this generally a consideration with sendAsynchronousRequest:queue:completionHandler: :?

Note. I found similar questions, but not specifically. for example, Does NSURLConnection block the main thread? indiekiduk specifically states that this is a new thread, although internal, I believe that this is not true, since I thought it was only at the end of the execution cycle, but I am still involved and probably / probably wrong.

+4
source share
2 answers

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

queues
The queue of operations to which the handler block is sent when the request is completed or> failure.

The block will be executed depending on which thread was transferred in the queue.

+5
source

The NSURLConnection sendAsync is scheduled on the RunLoop thread on the AFAIK so the block is called on the thread you are running.

0
source

Source: https://habr.com/ru/post/1446754/


All Articles