开发者

NSURLConnection returning zero length data

I had async NSURLConnections working just fine when I was using my viewController as the delegate, have all sorts of connections now and I want to do them all through a singleton Connection object. So I'm having Connection create a new delegate object for each connection it makes. Connection is instantiated in the app delegate, but the +(void)send:(Message *) function probably terminates.

My feeling about how this works is that the delegate listeners get put in the run loop (I'm not totally clear on this but I think they're not in separate threads. Shouldn't matter because the delegates allocate their own responseData memory.) and the connectionDidFinishLoading executes just fine, but with an empty responseData. By that I mean I find myself in connectionDidFinishLoading but responseData has zero bytes.

Code creating the app delegate (in the send method) is:

ConnectionDelegate *delegate = [[Conn开发者_StackOverflow社区ectionDelegate alloc] init];
NSURLConnection *connection=[[NSURLConnection alloc] initWithRequest:request delegate:delegate];

So my question is two folded:

  1. Is the problem that the send method terminates? The delegate pointer has local scope.

  2. If that's the problem, what can I do to keep the delegate alive?


You should double check your delegate's implementation of connection:didReceiveData:

Remember that you are responsible for collecting the incoming data segments there.

Please read Apple's doc(, especially URL loading system programming guide) and sample code again if any doubt.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜