0

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 response 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.

Mat
  • 202,337
  • 40
  • 393
  • 406
Adam
  • 589
  • 3
  • 8
  • 19
  • Have you tried it with a dummy returningResponse parameter? The class reference doesn't say that this parameter may be NULL (other than the error). Or maybe it's already in Apple's known bugs list. – ott-- Oct 16 '11 at 15:39
  • In my app, I actually don't use the nil parameter for the returningResponse or the error. The full code that I'm using is: NSURLResponse *serviceResponse = nil; NSError *serviceError = nil; NSData *response = [NSURLConnection sendSynchronousRequest: serviceRequest returningResponse: &serviceResponse error: &serviceError]; If I check the NSError after the call is made, it is null. If I check the NSURLResponse like this: NSLog(@"serviceResponse = %@", [serviceResponse URL]); It will show me the URL of the server that I contacted. – Adam Oct 16 '11 at 15:57
  • Your sample code runs successfully on my iOS5 simulator. If you post a more complete code example maybe we could replicate the problem you're having. – Steve Liddle Oct 18 '11 at 21:09

2 Answers2

2

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.

Josh Hight
  • 1,833
  • 2
  • 12
  • 5
0

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.

Mike
  • 1