方法一#import "Reachability.h"
  BOOL isExistenceNetwork = YES;
    Reachability *r = [Reachability reachabilityWithHostName:GetAdInfoList];
    switch ([r currentReachabilityStatus]) {
        case NotReachable:
            isExistenceNetwork=NO;
            NSLog(@"没有网络");
            break;
        case ReachableViaWWAN:
            isExistenceNetwork=YES;
            NSLog(@"正在使用3G网络");
            break;
        case ReachableViaWiFi:
            isExistenceNetwork=YES;
            NSLog(@"正在使用wifi网络");
            break;
    }
GetAdInfoList  可以是任意网址 例如 www.baidu.com
此方法需要添加 ASIRequest 第三方开源库


方法二 // 网络信息
    Reachability *reachability = [Reachability reachabilityWithHostName:@"www.apple.com"];
    //结果说明:0-无连接   1-wifi    2-3G
    NSInteger stateNet = [reachability currentReachabilityStatus];

#import "Reachability.h"百度一下 忘了包含哪个库了

方法三

https://developer.apple.com/library/ios/#samplecode/Reachability/Listings/Classes_ReachabilityAppDelegate_m.html#//apple_ref/doc/uid/DTS40007324-Classes_ReachabilityAppDelegate_m-DontLinkElementID_4
arrow
arrow
    全站熱搜

    戮克 發表在 痞客邦 留言(0) 人氣()