修改Reachability检测2g、3g、4g网络
1.在networkStatusForFlags:方法里面找到以下地方,替换即可。
1 if (flags & kSCNetworkReachabilityFlagsIsWWAN) { 2 if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) { 3 CTTelephonyNetworkInfo *info = [[CTTelephonyNetworkInfo alloc] init]; 4 NSString *currentRadioAccessTechnology = info.currentRadioAccessTechnology; 5 if (currentRadioAccessTechnology) { 6 if ([currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyLTE]) { 7 return kReachableVia4G; 8 } else if ([currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyEdge] || [currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyGPRS]) { 9 return kReachableVia2G; 10 } else { 11 return kReachableVia3G; 12 } 13 } 14 } 15 16 if ((flags & kSCNetworkReachabilityFlagsTransientConnection) == kSCNetworkReachabilityFlagsTransientConnection) { 17 if((flags & kSCNetworkReachabilityFlagsConnectionRequired) == kSCNetworkReachabilityFlagsConnectionRequired) { 18 return kReachableVia2G; 19 } 20 return kReachableVia3G; 21 } 22 return kReachableViaWWAN; 23 }
1 - (NSString *)nameWithInstance:(id)instance { 2 unsigned int ivarCount = 0;// 成员变量的数量 3 Ivar *ivars = class_copyIvarList([self class], &ivarCount);// 获取这个类的 成员变量 4 NSString *key = nil; 5 for (int i=0; i<ivarCount; i++) { 6 Ivar thisIvar = ivars[i]; 7 // 获取变量的类型,判断是否是对象 8 NSString *type = [NSString stringWithUTF8String:ivar_getTypeEncoding(thisIvar)]; 9 if (![type hasPrefix:@"@"]) { 10 continue; 11 } 12 if (object_getIvar(self, thisIvar) == instance) {// 获取实例对象的成员变量与传入实例对象的成员变量比较 13 key = [NSString stringWithUTF8String:ivar_getName(thisIvar)];// 取得实例对象的成员变量名称 14 break; 15 } 16 } 17 free(ivars); 18 return key; 19 } 20 21 #define varName(var) [NSString stringWithFormat:@"%s", #var] 22 NSString *abc = varName(abc); 23 NSLog(@"%@", abc);
时常一个人发呆,看到宁静的天空。