NSURLConnection和绑定的流对(CFStreamCreateBoundPair或CFStreamCreateBoundPairCompat)在iPhone 3G上不起作用 [英] NSURLConnection and bound pair of streams (CFStreamCreateBoundPair or CFStreamCreateBoundPairCompat) not working on iPhone 3G

查看:126
本文介绍了NSURLConnection和绑定的流对(CFStreamCreateBoundPair或CFStreamCreateBoundPairCompat)在iPhone 3G上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用SimpleURLConnections示例使用绑定的流对实现多部分/表单数据POST请求.在Simulator和iPhone 3GS/iPhone 4上都可以很好地工作.

I'm using SimpleURLConnections example to implement multipart/form-data POST request using bound pair of streams. It works great in Simulator and on iPhone 3GS/iPhone 4.

当我在iPhone 3G(运行3.1.3)上尝试时,没有数据发送到服务器. NSURLConnection一直保持挂起状态直到超时.经过一些测试,我发现仅当我对每个连接多次写入生产者流时,才会出现此问题.每当我需要编写不止一次(即必须响应多个NSStreamEventHasSpaceAvailable事件)时,事情就会停止工作.

When I try it on iPhone 3G (running 3.1.3) no data gets sent to the server. NSURLConnection just keeps hanging until it times out. After some testing I figured that the problem only occurs when I write to the producer stream more than once per connection. Whenever I need to write more than once (that is when I have to respond to more than one NSStreamEventHasSpaceAvailable event) things stop working.

这看起来像是同样的问题:带有HTTPBody输入流的NSURLRequest:流在打开之前发送事件,它确实提供了一种解决方法,但是我还没有弄清楚为解决该问题到底需要延迟什么.

This looks like the same issue: NSURLRequest with HTTPBody input stream: Stream sends event before being opened, and it does provide a workaround, but I haven't figured out what exactly I need to delay in order to fix the problem.

推荐答案

我遇到了同样的问题,似乎只有在数据适合网络堆栈缓冲区的情况下才会发送数据(这将解释为什么它可以在模拟器,其缓冲区可能比设备上的缓冲区大得多.

I had the same issue and it seems that the data will only be sent if it fits in the buffer of the network stack (this would explain why it works on simulator where the buffer is presumably much bigger than on the device).

为此,我们要解决的问题是延迟生产者流的调度.使用performSelector:withObject:afterDelay:,我们调用了一种方法,该方法可在1秒钟后在运行循环中安排输出流,这将使URL连接留有足够的时间来打开流.

The workaround we had for this was to delay scheduling of the producer stream. Using performSelector:withObject:afterDelay: we called a method which schedules the output stream on the run loop after 1 sec, which leaves the URL connection enough time to open the stream.

这篇关于NSURLConnection和绑定的流对(CFStreamCreateBoundPair或CFStreamCreateBoundPairCompat)在iPhone 3G上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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