[英]NSURLConnection and sendAsynchronousRequest:queue:completionHandler: - does the completion block run in the main thread
If I use NSURLConnection
with sendAsynchronousRequest:queue:completionHandler:
, do I need to take any particular precautions inside the completion handler? 如果我将
NSURLConnection
与sendAsynchronousRequest:queue:completionHandler:
,我是否需要在完成处理程序中采取任何特殊的预防措施? 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? 具体来说,是通过
NSURLConnection
直接异步发送与使用dispatch_async
相同/相似,因为完成块需要返回主线程与UI交互?
For example: after using dispatch_async
to interact (maybe the wrong word) with the UI, the app must use performSelectorOnMainThread
. 例如:在使用
dispatch_async
与UI交互(可能是错误的单词)后,应用程序必须使用performSelectorOnMainThread
。
Is that a consideration at all with sendAsynchronousRequest:queue:completionHandler:
? 这是
sendAsynchronousRequest:queue:completionHandler:
一个考虑sendAsynchronousRequest:queue:completionHandler:
?
note: I have found similar questions, but not this specifically. 注意:我发现了类似的问题,但没有具体说明。 eg, in Does NSURLConnection block the main thread?
例如,在NSURLConnection中阻止主线程吗? 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.
indiekiduk特别指出它是一个新的线程,虽然是一个内部的 - 我认为这是有缺陷的,因为我认为它只是在运行循环结束 - 但我仍然在学习,可能/可能是错误的。
The documentation for NSURLConnection
states for the queue parameter to sendAsynchronousRequest:queue:completionHandler:
NSURLConnection
的文档说明sendAsynchronousRequest:queue:completionHandler:
的queue参数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. 该块将在传入的队列中设置的任何线程上执行。
NSURLConnection sendAsync是在AFAIK上的线程的RunLoop上调度的,所以在启动它的线程中调用该块
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.