为什么我应该更喜欢 ASIHTTPRequest 而不是 NSURLConnection 从网络下载文件?
我见过几次人们使用 ASIHTTPRequest 来下载文件。现在我想知道为什么?与 NSURLConnection 相比,核心优势是什么?
I've seen a couple of times people using ASIHTTPRequest to download files. Now I wonder why? What are the core benefits over NSURLConnection?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
有几个原因。在我看来,这些是主要的:
ASIHTTPRequest
允许为每个请求指定一个委托(而不是为整个NSURLConnection
指定一个委托);这很有用,因为一旦您获得了正在等待的数据,每个请求原则上都会有不同的处理;ASIHTTPRequest
支持缓存机制,可以让您的应用程序在离线时轻松运行(并显示缓存的数据); NSURLRequest 中没有这样的机制;如果您搜索 stackoverflow,您会发现许多关于非常奇怪的内存泄漏的提示,
NSURLConnection/NSURLRequest
激发;ASIHTTRequest
没有遇到这种情况;ASIHTTRequest
提供了更好的 Reachability 实现,这是绝对必要的; Apple 提供的一个据说有问题。< /p>希望这有帮助。
There are several reasons. In my mind these are the major ones:
ASIHTTPRequest
allows to specify a delegate for each request (vs. one delegate for a wholeNSURLConnection
); this is useful because each request has in principle a different processing once you get the data you were waiting for;ASIHTTPRequest
supports a caching mechanism that make very easy to make your app working when offline (and showing the cached data); no such mechanism in NSURLRequest;If you search stackoverflow, you will find many hints at a very strange memory leak that
NSURLConnection/NSURLRequest
provoke; this is not experienced withASIHTTRequest
;ASIHTTRequest
offers a better implementation of Reachability, which is absolutely necessary; the Apple provided one is said to be buggy.Hope this helps.
ASIHTTPRequest
明显更容易使用。您不必手动连接数据块,POST 请求很容易构造,支持块,ASIHTTPRequest
是NSOperation
的子类,因此您可以轻松对请求进行排队, ETC。ASIHTTPRequest
is just significantly easier to use. You don't have to concatenate data blocks manually, POST requests are easy to construct, blocks are supported,ASIHTTPRequest
is a subclass ofNSOperation
so you can easily queue up your requests, etc.恕我直言,ASIHTTPRequest 的优点是:
ASIHTTPRequest's strength points are IMHO:
恕我直言,这归结为程序员的易用性。它非常容易使用,并且有非常详细的文档记录。您可以非常轻松地使用队列并通过委派管理其状态。
在文件范围之外,与内置的 NSURL 类相比,使用 ASI 处理响应委托一定更容易。
IMHO it comes down to ease of use for the programmer. It's very easy to work with and is incredibly well documented. You can very easily use queues and manage their status via delegation.
Outside the scope of files it is must easier to handle response delegation using ASI compared to the built in NSURL classes.