OStack程序员社区-中国程序员成长平台

标题: ios - 对可达性类的 iPv6 支持 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 11:38
标题: ios - 对可达性类的 iPv6 支持

我在我的应用程序中使用可达性类来监控网络状态。 Apple 在他们的文档中提到提供对 IPv6 类型的支持。

我发现一些 iPV4 类型在可达性类中使用。 我已经搜索了新的可达性类,但没有找到.. 是否有任何新的检查 iPv6 网络可达性状态的类?

   + (Reachability*) reachabilityForLocalWiFi;
    {
        struct sockaddr_in localWifiAddress;
        bzero(&localWifiAddress, sizeof(localWifiAddress));
        localWifiAddress.sin_len = sizeof(localWifiAddress);
        localWifiAddress.sin_family = AF_INET;
        // IN_LINKLOCALNETNUM is defined in <netinet/in.h> as 169.254.0.0
        localWifiAddress.sin_addr.s_addr = htonl(IN_LINKLOCALNETNUM);
        Reachability* retVal = [self reachabilityWithAddress: &localWifiAddress];
        if(retVal!= NULL)
        {
            retVal->localWiFiRef = YES;
        }
        return retVal;
    }



Best Answer-推荐答案


找到这个 on Apple's forums .它最好地描述了这个问题的现状:

Q: "We are using reachabilityForLocalWiFi from reachability class? I notice reachabilityForLocalWiFi method is using reachabilityWithAddress (local ip address)? I am wondering how will it work for the ivp6 address? Currently it works for ipv4 address."

A: (By "the Eskimo"): "I don’t think that will be a problem. Even if the device only has IPv6 connectivity to the outside world, it should still be able to get to link-local IPv4 addresses (169.254/16), which is what +reachabilityForLocalWiFi uses."

关于ios - 对可达性类的 iPv6 支持,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33404481/






欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) Powered by Discuz! X3.4