NSUrlConnection ASynchronous究竟是什么意思? [英] what exactly NSUrlConnection ASynchronous means?

查看:128
本文介绍了NSUrlConnection ASynchronous究竟是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很困惑Synchronous NSUrlConnection和ASynchronous NSUrlConnection之间的区别是什么?是同步还是异步?如果我们在connectionDidFinishLoading方法中使用detachNewThreadSelector,那么它是
ASynchronous NSUrlConnection吗?这是最好的方法吗?任何教程...

i am getting confused what is the difference between Synchronous NSUrlConnection and ASynchronous NSUrlConnection?is there Synchronous or ASynchronous? if we use detachNewThreadSelector in connectionDidFinishLoading method,is it ASynchronous NSUrlConnection? which is the best way?any tutorial ...

推荐答案

同步意味着你触发 NSURLConnection 请求并等待它完成。

Synchronous means that you trigger your NSURLConnection request and wait for it to be done.

异步意味着您可以在 NSURLConnection时触发请求并执行其他操作下载数据。

Asynchronous means that you can trigger the request and do other stuff while NSURLConnection downloads data.

哪个是最好的?

同步非常简单:你设置它,触发它,然后等待数据返回。但是您的应用程序位于那里并且在下载所有数据,发生一些错误或请求超时之前什么都不做。如果您处理的不仅仅是少量数据,那么您的用户将坐在那里等待,这将无法提供良好的用户体验。

Synchronous is very straightforward: you set it up, fire it, and wait for the data to come back. But your application sits there and does nothing until all the data is downloaded, some error occurs, or the request times out. If you're dealing with anything more than a small amount of data, your user will sit there waiting, which will not make for a good user experience.

异步需要更多的工作,但你的用户可以做请求做其他事情,这通常是更好的。您可以设置一些委托方法,以便在数据进入时跟踪数据,这对跟踪下载进度非常有用。对于大多数使用情况,这种方法可能更好。

Asynchronous requires just a little more work, but your user can do other stuff while the request does its thing, which is usually preferable. You set up some delegate methods that let you keep track of data as it comes in, which is useful for tracking download progress. This approach is probably better for most usage cases.

您可以使用 NSURLConnection 执行同步和异步请求。 Apple的文档提供了明确的解释后一种方法所需的两种方法和委托方法。

You can do both synchronous and asynchronous requests with NSURLConnection. Apple's documentation provides a clear explanation of the two approaches and delegate methods required for the latter approach.

这篇关于NSUrlConnection ASynchronous究竟是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆