4

I am using reachability class in my application to monitor the network state.The following are the code to check reachability of the internet from the Apple reachability sample. It works well with IPv4 networks. But it fails on IPv6 wifi networks.


+ (instancetype)reachabilityForInternetConnection
{
struct sockaddr_in zeroAddress;
bzero(&zeroAddress, sizeof(zeroAddress));
zeroAddress.sin_len = sizeof(zeroAddress);
zeroAddress.sin_family = AF_INET;
return [self reachabilityWithAddress:&zeroAddress];
}


 So now we are in the process of supporting IPv6 network as well from our application. When we have upgrade these code  to support IPv6 as follows. 
         

        struct sockaddr_in6 zeroAddress;
        bzero(&zeroAddress, sizeof(zeroAddress));
        zeroAddress.sin6_len = sizeof(zeroAddress);
        zeroAddress.sin6_family = AF_INET6;
        return [self reachabilityWithAddress: &zeroAddress];


The above IPv6 support code works well in the iOS9 & later devices for both IPv4&IPv6 wifi networks. But on iOS8 device its failing for the IPV4 networks. So is there any update available on the Apple's reachability code to support IPV6 network as well. 
 Any help would be appreciated. Thanks in advance.

  • I am using reachability class in my application to monitor the network state. Whenever there is change in the wifi state (switching network, turnoff wifi , etc ). For all these cases my application will be notified by networkReachabilityChanged call back. Once this notifcation arrived our application will try to login to that hotspot or it will update the Main UI if the connection is already availbale. For the same Im looking with IPv6 nework support. – user1856666 Jan 25 '16 at 12:46

1 Answers1

0

I think if you replace with below Code then It will work for you.

+(Reachability*)reachabilityWithHostName:(NSString*)hostname
{
   return [Reachability reachabilityWithHostname:hostname];
}

And one more

+(Reachability*)reachabilityWithHostname:(NSString*)hostname
{
SCNetworkReachabilityRef ref = SCNetworkReachabilityCreateWithName(NULL, [hostname UTF8String]);
if (ref) 
{
    id reachability = [[self alloc] initWithReachabilityRef:ref];

    return reachability;
}

return nil;
}

Initialize Reachability Class with you can use "google.com" as domain Name to check internet connection.

  Reachability *r = [Reachability reachabilityForInternetConnection:@"your domain here"];

I hope this would help you.