Reachability.h布尔变量connectionRequired - 这简单来说意味着什么?

时间:2013-06-07 04:37:58

标签: ios networking reachability

connectionRequired变量在Apple编写的Reachability.h类中意味着什么?用简单的英语?

//WWAN may be available, but not active until a connection has been established.
//WiFi may require a connection for VPN on Demand.
- (BOOL) connectionRequired;

是不是意味着:

- 你可以连接,但你没有连接? - 你需要一个密码 - 你需要VPN

我何时需要检查此变量是否为真?

2 个答案:

答案 0 :(得分:2)

这意味着手机具有可用的互联网连接,但配置为通过VPN隧道连接,无法连接到VPN服务器。以这种方式配置的电话通常是公司电话,可以访问内部网和跟踪电话活动等。

理想情况下,当您检查互联网连接时,应始终检查此项,因为除非所有者在“设置”中将其关闭,否则手机将无法再获取任何数据,直到VPN服务器再次可用。

答案 1 :(得分:0)

来自Reachability.m

    if ((flags & kSCNetworkReachabilityFlagsConnectionRequired) == 0)
    {
        // if target host is reachable and no connection is required
        //  then we'll assume (for now) that your on Wi-Fi
        retVal = ReachableViaWiFi;
    }

...

- (BOOL) connectionRequired;
{
    NSAssert(reachabilityRef != NULL, @"connectionRequired called with NULL reachabilityRef");
    SCNetworkReachabilityFlags flags;
    if (SCNetworkReachabilityGetFlags(reachabilityRef, &flags))
    {
        return (flags & kSCNetworkReachabilityFlagsConnectionRequired);
    }
    return NO;
}

来自AppDelegate.m

    if(connectionRequired)
    {
        baseLabel=  @"Cellular data network is available.\n  Internet traffic will be routed through it after a connection is established.";
    }
    else
    {
        baseLabel=  @"Cellular data network is active.\n  Internet traffic will be routed through it.";
    }

因此,它大致说明设备是使用Wi-Fi还是3G以及连接是否处于活动状态或设备是否会建立连接。如果用户使用VPN,设备将首先要求他建立VPN连接。