Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect internet connection when connected to wifi but no intenernet: iOS

Tags:

ios

I just want to know how to detect internet connectivity in iOS when device is connected to wifi but no intenet connection in modem.

I have used apple's and AFNetworking's reachability but they only check for connectivity and returns connected flag even there is no working internet in modem.

like image 688
Mayank Jain Avatar asked Oct 19 '22 03:10

Mayank Jain


1 Answers

I found the solution by hitting host via Reachability:-

Might be helpful for someone.

-(BOOL)isCheckConnection {
    Reachability *rc = [Reachability reachabilityWithHostName:@"www.google.com"];
    NetworkStatus internetStatus = [rc currentReachabilityStatus];

    if(internetStatus==0)
    {
        //@"NoAccess";
        return NO;
    }
    else if(internetStatus==1)
    {
        //@"ReachableViaWiFi";
        return YES;
    } else if(internetStatus==2)
    {
        //@"ReachableViaWWAN";
        return YES;
    }
    else
    {
        //@"Reachable";
        return YES;
    }
}
like image 150
Mayank Jain Avatar answered Nov 01 '22 10:11

Mayank Jain