I used the following code to check this—
(the request is my request)
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if( theConnection )
{
nslog(@"connection is present");
}
else
{-------error message1-------------
}
and then in the delegates I relay on to receive response
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{
-------error message2-------------
}
I am presently checking everything on my simulator…and…detecting internet connection by just removing my internet cable…
but every time my program I got only message 2…..but it comes after 1 min(connection time over)…
but I want to check it in as minimum time as possible….
You may want to take a look at the Reachability exaxmple provided by Apple.
If you want your NSURLConnection to fail earlier, you need to specify a timeout in your NSURLRequest:
requestWithURL:cachePolicy:timeoutInterval: