Sameer
Sameer

Reputation: 89

IOS Checking Active internet connection even connected via WIFI without internet

Please help me out how to check internet connection in iPhone.

I tried by checking the Apple's reachability framework, but it is not returning if connected via WIFI without internet.

What I am getting is reachable via wifi.

The other option I tried is making a synchronous request with google.com etc and checking the response code.

Is there any other way to check so that I can avoid making a url request and checking the response code.

Thanks in advance.

Upvotes: 0

Views: 742

Answers (1)

l0gg3r
l0gg3r

Reputation: 8954

Check if wifi reachable (using Apple's reachability), and then make request to ensure host is reachable.

// wifi checking code here
//...
[[[NSURLSession sharedSession] dataTaskWithURL:[NSURL URLWithString:@"http://yourServer.com/someLightFile.html"] completionHandler:^(NSData *data, NSURLResponse *response, NSError *error)
{
    if (!error) {
        // Your host is reachable
    }
}] resume];

Upvotes: 1

Related Questions