iPhone开发 判断当前的网络是3g还是wifi

1.添加framework:
将SystemConfiguration.framework 添加进工程。

2.下载https://developer.apple.com/library/ios/samplecode/Reachability/Reachability.zip 

复制里面的Reachability.h和Reachability.m到项目中

 

 

调用的代码:

//判断当前的网络是3g还是wifi

-(NSString*)GetCurrntNet

{

    NSString* result;

    Reachability *r = [ReachabilityreachabilityWithHostName:@"www.apple.com"];

    switch ([r currentReachabilityStatus]) {

        caseNotReachable:// 没有网络连接

            result=nil;

            break;

        caseReachableViaWWAN:// 使用3G网络

            result=@"3g";

            break;

        caseReachableViaWiFi:// 使用WiFi网络

            result=@"wifi";

            break;

    }

    return result;

}

posted @ 2012-03-01 11:09  凡娃软件  阅读(515)  评论(0编辑  收藏  举报