您的位置:首页 > 理论基础 > 计算机网络

判断Iphone,Ipad当前网络状态

2012-03-16 11:11 183 查看
1、到苹果管网下载Reachability的Demo,https://developer.apple.com/library/ios/#samplecode/Reachability/Introduction/Intro.html

然后把:Reachability.h 和 Reachability.m 添加到工程中

2、使用如下方法就能判断当前是否联网:

bool CCNetworkConfig::isNetworkAvailable()
{
    Reachability *r = [ReachabilityreachabilityWithHostName:@"www.apple.com"];
    switch ([rcurrentReachabilityStatus]) {
        caseReachableViaWWAN: // 使用3G网络
            printf("current network 3g/gprs\n");
            return true;
        caseReachableViaWiFi: // 使用WiFi网络
            printf("current network wifi\n");
            return true;
        caseNotReachable: // 没有网络连接
        default:
            break;
    }
    printf("current network none\n");
    return false;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  网络 iphone ipad network