iphone - 如何使用 ASIHTTPRequest 处理低互联网连接

标签 iphone objective-c ios networking asihttprequest

我正在开发一个执行大量 API 获取的应用程序,如果互联网连接速度非常低,比如说 5 kbps,应用程序就会在 main 方法中崩溃。 我认为当队列中有很多请求时会发生这种情况,因此操作系统会终止应用程序。 我正在使用 ASIHTTPRequest 和基于 block 的异步请求。

我该如何解决这个问题?

最佳答案

您需要为整个应用程序使用单一网络队列。严重依赖互联网连接的应用程序应该优化并发网络操作的数量。不幸的是,ASIHTTPRequest 框架不会这样做。我建议您使用 MKNetworkKit,它是专门为移动应用而构建的。

Most mobile networks (3G) don’t allow more than two concurrent HTTP connections from a given IP address. Edge is even worse. You can’t, in most cases, open more than one connection. This limit is considerably high (six) on a traditional home broadband (Wifi). On any normal case, the iDevice is mostly connected to a 3G network, which means, you are restricted to upload only two photos in parallel. Now, it is not the slow upload speed that hurts.

The real problem arises when you open a view that loads thumbnails of photos (say on a different view) while this uploading operations are running in the background. When you don’t properly control the queue size across the app, your thumbnail loading operations will just timeout which is not really the right way to do it. The right way to do this is to prioritize your thumbnail loading operation or wait till the upload is complete and the load thumbnails. This requires you to have a single queue across the entire app. MKNetworkKit ensures this automatically by using a single shared queue for every instance of it. While MKNetworkKit is not a singleton by itself, the shared queue is.

source

关于iphone - 如何使用 ASIHTTPRequest 处理低互联网连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14135084/

相关文章:

objective-c - 在 Cocoa 中同时显示多个工具提示

ios - JSON 解析,嵌套 JSON 结构问题

iphone - 最好的手机开发数据库

ios - 当前 UIImagePickerController 导致我的应用程序在 iOS6.1 下崩溃

iphone - 按下 TableView 时单击按钮以记住值

ios - 在 Swift 中使用 "= {}()"声明类属性的性质是什么?

ios - 如何在 iOS 中播放来自服务器的流式 PCM 数据?

iPhone:用于将网络图像(url)存储为文件(散列文件名)的快速哈希函数

ios - 使用 Core Animation 的 Glitch-style 动画

ios - 在 objective-c 中的一段时间间隔后自动在应用程序中检查互联网可用性