gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 22:42:23 24 4
gpt4 key购买 nike

我正在开发一个执行大量 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com