wifi is connected and internet is not available iOS

498 views Asked by At

My question is same as this question, but don't get a proper answer.

If I am connected to wifi, but internet is not available/gone it should be notify. Alslo tested using Apple Reachability demo but still its not working.

Steps to reproduce:

1) connect iPhone using tethering on another device.

2) run the apple rechability demo.

3) turn off the cellular data on another device on wich iPhone is connected.

1

There are 1 answers

2
ZoobieDoobie On

You can simply call the below code and then call NSURLConnection delegate methods. This way even if wifi is connected and internet not available it can be detected.

NSMutableURLRequest *headerRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.com"] cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:10.0];
    headerRequest.HTTPMethod = @"HEAD";
    self.headerConnection = [[NSURLConnection alloc] initWithRequest:headerRequest delegate:self];