iOS 网络监测(wifi与3G)

使用之前请从Apple网站下载示例:https://developer.apple.com/library/ios/samplecode/Reachability/Reachability.zip

然后将Reachability.h 和 Reachability.m 加到自己的项目中,并引用 SystemConfiguration.framework,就可以使用了。
Reachability 中定义了3种网络状态:

// 是否wifi
+ (BOOL) IsEnableWIFI {
    return ([[Reachability reachabilityForLocalWiFi] currentReachabilityStatus] != NotReachable);
}

// 是否3G
+ (BOOL) IsEnable3G {
    return ([[Reachability reachabilityForInternetConnection] currentReachabilityStatus] != NotReachable);
}

// 有无网络访问
if ([[Reachability reachabilityForLocalWiFi] currentReachabilityStatus] == NotReachable && [[Reachability reachabilityForInternetConnection] currentReachabilityStatus] == NotReachable) {
        NSLog(@"无网络访问,请检查是否连接网络!");
}

你可能感兴趣的:(iOS 网络监测(wifi与3G))