升级到iOS 5后NSURLConnection失败 [英] NSURLConnection fails after upgrade to iOS 5
问题描述
我有一个非常简单的NSURLConnection调用,在iOS 5以外的所有iOS版本中都能正常工作。因为这是一个'sendSynchronousRequest'调用,所以在应用程序的任何地方都没有声明NSURL委托(响应应该直接回到这个方法)呼叫)。此外,因为这是一个sendSynchronousRequest,所以在应用程序中没有实现'didReceiveData'或其他与NSURL相关的方法。
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.
这一切都运行良好,直到我升级到iOS 5.现在,在更新到iOS5之后,NSData变量(响应)永远不会收到任何东西,并且总是回来0字节。
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.
除了对iOS5的更新外,根本没有代码更改。
Other than the update to iOS5, there have been no code changes at all.
推荐答案
在iOS 5中对NSURLConnection类进行了一些更改。特别是,不推荐使用了几个委托方法。我遇到了类似的问题,它是由一个不再被调用的委托方法引起的。如果这听起来像你的问题,看看正式委托协议 NSURLConnectionDelegate
和 NSURLConnectionDataDelegate
。
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
.
这篇关于升级到iOS 5后NSURLConnection失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!