What is the situation regarding the NSURLConnection timeout with iOS5?

最后都变了- 提交于 2019-12-06 04:48:26

问题


I'm trying to find a definitive answer to if it possible to set the timeout value for using NSURLConnection in iOS 5 (I would like to set it to 30 seconds).

I've searched past postings on this but the information seems contradictory. For example, this posting

NSURLConnection timeout?

says Apple mandates a 4 minute minimum timeout - though I cannot find any Apple documentation to support this.

THis posting says the 240 limit comes from an apple forum thread NSMutableURLRequest not obeying my timeoutInterval

They say this limit is only for POSTs when the body isn't empty. Does that imply its possible to set the timeout less than 4 minutes for GETS?

Somebody commented here that that's not the case with iOS 5, however they were down voted NSMutableURLRequest not obeying my timeoutInterval

And there's other's saying other things but anyway most of the previous postings on this topic seem to be from a couple of years ago prior to iOS 5.

If there is a 4 minute limit then having to rely on hearsay to know this is a bit ridiculous if there truly is no Apple documentation.

Does anybody know the actual definitive situation on this for iOS 5.


回答1:


It is not the connection that has an associated timeout, it is the request (that is made over the connection). See the documentation for NSURLRequest. The timeout interval is measured in seconds (not minutes, which is but a clue).

Return Value The receiver's timeout interval, in seconds.

Discussion If during a connection attempt the request remains idle for longer than the timeout interval, the request is considered to have timed out.*

Various Apple code and documentation show timeouts of 60 seconds; thus 4 minutes can't be the minimum.




回答2:


In my experience I have found that: - Its possible to set a timeout value of anything (i.e. 0.1 seconds) for HTTP GETS. - The OS does impose a limit of 240 for HTTP POSTS with a body.



来源:https://stackoverflow.com/questions/10889060/what-is-the-situation-regarding-the-nsurlconnection-timeout-with-ios5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!