我正在使用NSMutableURLRequest连接到网站以获取JSON响应。我这样做是通过生成请求,然后使用NSURLConnection与self的委托来处理异步连接。我已经实现了所有正常的委托方法:
I'm using a NSMutableURLRequest to connect to a web site to get a JSON response. I'm doing so by generating the request, and then using NSURLConnection with a delegate of self to handle the async connection. I've implemented all the normal delegate methods:
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error - (void)connectionDidFinishLoading:(NSURLConnection *)connection所有这些都可以很好地恢复数据,处理发生的任何错误等。但是,如果将NSURLRequest上的超时设置为10秒,我就不会似乎在这些方法中被调用(我希望调用didFailWithError)。它只是永远坐在那里,我没有通知它超时。
All works perfectly with getting data back, dealing with any errors that occur, etc. However with the timeout on the NSURLRequest set to 10 seconds I don't seem to get called in those methods (I expected the didFailWithError to get called). It just sits there forever and I have no notification that it timed out.
阅读iPhone API文档我没有看到任何提及应该在超时发生时发生,只是你可以设置超时值。应该怎么办?我没有在API中看到任何其他有用的委托方法。我不必手动检查超时,是吗?超时仅适用于同步请求吗?
Reading the iPhone API docs I don't see any mention of what should happen when the timeout occurs, just that you can set the timeout value. What should happen? I didn't see any other delegate methods in the API that would help. I don't have to manually check for timeouts, do I? Are timeouts only for synchronous requests?
推荐答案此方法收到您的超时:
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error更多推荐
使用委托时,使用超时处理NSURLRequest
发布评论