Reputation: 89
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
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