简体   繁体   English

NSURLConnection和sendAsynchronousRequest:queue:completionHandler: - 完成块是否在主线程中运行

[英]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? 如果我将NSURLConnectionsendAsynchronousRequest: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.

相关问题 NSURLConnection sendAsynchronousRequest完成块是否在主线程上执行? - Is NSURLConnection sendAsynchronousRequest completion block executed on the main thread? NSURLConnection connectionWithRequest:delegate和sendAsynchronousRequest:queue:completionHandler之间的主要区别是什么? - What is the main difference between NSURLConnection connectionWithRequest:delegate and sendAsynchronousRequest:queue:completionHandler? NSURLConnection sendAsynchronousRequest:queue:completionHandler在iOS 4.3中不起作用 - NSURLConnection sendAsynchronousRequest:queue:completionHandler not working in iOS 4.3 iOS4的实现 - [NSURLConnection sendAsynchronousRequest:queue:completionHandler:]? - iOS4 Implementation of -[NSURLConnection sendAsynchronousRequest:queue:completionHandler:]? NSURLConnection sendAsynchronousRequest:queue:completionHandler:HTTP或HTTPS - NSURLConnection sendAsynchronousRequest:queue:completionHandler: HTTP or HTTPS connectionDidFinishLoading:不使用[NSURLConnection sendAsynchronousRequest:队列:complementHandler: - connectionDidFinishLoading: not called with the use of [NSURLConnection sendAsynchronousRequest: queue: completionHandler: [NSURLConnection sendAsynchronousRequest:...]是否总是发送完成块? - Will [NSURLConnection sendAsynchronousRequest: …] always send completion block? NSURLConnection sendAsynchronousRequest:queue:completionHandler:连续发出多个请求? - NSURLConnection sendAsynchronousRequest:queue:completionHandler: making multiple requests in a row? 如何使用sendAsynchronousRequest:queue:completionHandler: - how to use sendAsynchronousRequest:queue:completionHandler: sendAsynchronousRequest:queue:completionHandler:具有委托方法 - sendAsynchronousRequest:queue:completionHandler: With Delegate Methods
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM