Handling a NSURLRequest with timeout when using delegate

别来无恙 提交于 2019-12-03 12:57:49

Your timeout is received in this method:

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
Sandeep Kumar

u will br receiving such type of iofo:

in did fail with

error: Error Domain=NSURLErrorDomain Code=-1001 UserInfo=0xed4870 "timed out"

The timeout behaviour is a bit quirky, see this thread on Apple’s developer forums.

What I did was this:

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{
    if (error.code == -1001){
        [self showTimeoutAlert];//My method to show dialog with timeout message.
    } else {
        [self showInvalidURLAlert];//My method to show dialog with bad URL message.
    }
}

As said before -1001 is for timeout, in other tests I got -1003 (for bad URL or no connection avaliable).

I was aiming to treat timeout so anything else I treated as bad URL.

Sandeep Kumar

Put some log statements in each method and check what they give. Whenever it times out, you definitely get a notification on the console about the timeout. I am getting that notification . Check your code and if you are still have problems, let us know.

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