开发者

NSURLConnection fails after upgrade to iOS 5

开发者 https://www.devze.com 2023-04-13 03:40 出处:网络
I have a very simple NSURLConnection call that works perfectly in all iOS versions except iOS 5.Since this is a \'sendSynchronousRequest\' call, there are no NSURL delegates declared anywhere in the a

I have a very simple NSURLConnection call that works perfectly in all iOS versions except iOS 5. Since this is a 'sendSynchronousRequest' call, there are no NSURL delegates declared anywhere in the app (the respo开发者_StackOverflow中文版nse should come directly back to this method call). Also, because this is a sendSynchronousRequest, there are no 'didReceiveData' or other NSURL-associated methods implemented in the app.

Here is the offending line of code:

NSData *response = [NSURLConnection sendSynchronousRequest: serviceRequest returningResponse:nil error:nil];

When I step through the code in the debugger, I can confirm that app is sending the request, and that the server is receiving the request. I can also confirm that the server is then sending a response back to the client.

This was all working perfectly until I upgraded to iOS 5. Now, after the update to iOS5, the NSData variable (response) is never receiving anything and always comes back with 0 bytes.

Other than the update to iOS5, there have been no code changes at all.


There were several changes made to the NSURLConnection class in iOS 5. In particular, several delegate methods that were deprecated. I experienced a similar issue and it was caused by one of the delegate methods no longer being called. If this sounds like your issue, take a look at the formal delegate protocols NSURLConnectionDelegate and NSURLConnectionDataDelegate.


I had the same problem using a custom Web server. The problem turned out to be an invalid header in the response. I changed:

HTTP/1.1 200/OK

to:

HTTP/1.1 200 OK

iOS 5 now accepts the response. Check your packet capture. You may have the same or similar problem.

0

精彩评论

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