[英]NSURLConnection and sendAsynchronousRequest:queue:completionHandler: - does the completion block run in the main thread
[英]Is NSURLConnection sendAsynchronousRequest completion block executed on the main thread?
我想知道当我使用NSURLConnection sendAsynchronousRequest
时是否在主线程上调用completionHandler
NSURLConnection sendAsynchronousRequest
。 我主要关心的是我是否需要自己在主线程上分派UIKit
调用。
除非我错过了,否则NSURLConnection
的文档没有提及此细节。
我分析了我的代码,没有内存泄漏,这表明该块是在主线程上执行的。
有没有给出明确答案的文件?
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
[self.progress stopAnimating];
if (data != nil) {
...
} else {
[self showMessageIgnoreAcknowledgement:@"Error" message:@"blah"];
}
}];
从NSURLConnection sendAsynchronousRequest:queue:completionHandler:
的文档中,使用NSURLConnection sendAsynchronousRequest:queue:completionHandler:
方法:
当请求完成或失败时,加载URL请求的数据并在操作队列上执行处理程序块。
同样从关于queue
参数的注释中:
请求完成或失败时,将处理程序块调度到的操作队列。
由于您要传入主队列,因此完成处理程序将位于主线程上(主队列位于主线程上)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.