How to detect loss of internet reachability when wifi source loses connection?

后端 未结 3 1625
日久生厌
日久生厌 2021-02-04 16:10

I am trying hard to get the authentic internet connectivity status. I have used Apple\'s Reachability but it\'s only giving me the status of wifi connectivity i.e. not covering

3条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-04 16:39

    According to Reachability it checks for not only wifi but also for WWAN/3G and no internet access, why do you think it does not check other than WIFI?

     typedef enum {
    
        NotReachable = 0,
    
        ReachableViaWiFi,
    
        ReachableViaWWAN
    
    } NetworkStatus;
    

    if you want to check the reachability to a particular host then you could set the host yourself like this

    Reachability *hostReach = [Reachability reachabilityWithHostName: @"www.google.com"];
    
    NetworkStatus netStatus = [hostReach currentReachabilityStatus];
    
     switch (netStatus)
        {
            case ReachableViaWWAN:
            {
                NSLog(@"WWAN/3G");
                break;
            }
            case ReachableViaWiFi:
            {
                NSLog(@"WIFI");
                break;
            }
            case NotReachable:
            { 
                NSLog(@"NO Internet");
                break;
            }
    }
    

提交回复
热议问题