判断Iphone,Ipad当前网络状态

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;

}


posted @ 2012-02-06 17:04  MXi4oyu  阅读(206)  评论(0编辑  收藏  举报