IOS reachability class for ipv6 support

I use the reachability class in my application to monitor network status. Below is the code for checking Internet availability from Apple's accessibility sample. It works well with IPv4 networks. But it does not work on IPv6 Wi-Fi 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 the IPv6 network, as well as our application. When we update this code to support IPv6, follow these steps:

        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 on iOS9 and later devices for IPv4 and IPv6 Wi-Fi networks. But on iOS8, it does not work for IPV4 networks. So, is there an available update for the Apple Availability Code to support IPV6 network. Any help would be greatly appreciated. Thanks in advance.

+4
1

, , .

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

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

    return reachability;
}

return nil;
}

"google.com" , .

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

, .

0

Source: https://habr.com/ru/post/1625802/


All Articles