标签:style http color io os ar strong 文件 数据
由于流量精灵需要在 蜂窝数据或者3G 环境下进行流量监控因此需要判定3G 环境
将 SystemConfiguration.framework 添加进工程:
+(BOOL) isNetworkEnabled
{
BOOL bEnabled = FALSE;
NSString *url = @"www.baidu.com";
SCNetworkReachabilityRef ref =SCNetworkReachabilityCreateWithName(NULL, [urlUTF8String]);
SCNetworkReachabilityFlags flags;
bEnabled = SCNetworkReachabilityGetFlags(ref, &flags);
CFRelease(ref);
if (bEnabled) {
// kSCNetworkReachabilityFlagsReachable:能够连接网络
// kSCNetworkReachabilityFlagsConnectionRequired:能够连接网络,但是首先得建立连接过程
// kSCNetworkReachabilityFlagsIsWWAN:判断是否通过蜂窝网覆盖的连接,比如EDGE,GPRS或者目前的3G.主要是区别通过WiFi的连接。
BOOL flagsReachable = ((flags &kSCNetworkFlagsReachable) != 0);
BOOL connectionRequired = ((flags &kSCNetworkFlagsConnectionRequired) != 0);
BOOL nonWiFi = flags &kSCNetworkReachabilityFlagsTransientConnection;
bEnabled = ((flagsReachable && !connectionRequired) || nonWiFi) ? YES : NO;
}
return bEnabled;
}
当作记录吧
标签:style http color io os ar strong 文件 数据
原文地址:http://www.cnblogs.com/kingbo/p/4001838.html