获取当前网络连接的强度0-100,当前网络类型
#import <dlfcn.h>
- (NSDictionary *)getWifiSignalStrength{
NSString*networkType = [selfgetNetworkType];
void *libHandle = dlopen("/System/Library/Frameworks/CoreTelephony.framework/CoreTelephony", RTLD_LAZY);
int(*CTGetSignalStrength)(void);
CTGetSignalStrength =dlsym(libHandle,"CTGetSignalStrength");
intsignalStrengthrr = CTGetSignalStrength();
return@{@"netWorkType":networkType,@"netWorkStrength":[NSStringstringWithFormat:@"%d",signalStrengthrr]};
}
//获取网络类型---这个可以自己实现
- (NSString *)getNetworkType{
if([NetworkMonitoring sharedNetworkMonitoring].networkStatus == NetworkStatusNotReachable){
return@"NONE";
}else if ([NetworkMonitoring sharedNetworkMonitoring].networkStatus == NetworkStatusUnknown){
return@"NONE";
}else if ([NetworkMonitoring sharedNetworkMonitoring].networkStatus == NetworkStatusWWAN2G){
return@"2G";
}else if ([NetworkMonitoring sharedNetworkMonitoring].networkStatus == NetworkStatusWWAN3G){
return@"3G";
}else if ([NetworkMonitoring sharedNetworkMonitoring].networkStatus == NetworkStatusWWAN4G){
return@"4G";
}else if ([NetworkMonitoring sharedNetworkMonitoring].networkStatus == NetworkStatusWiFi){
return@"WIFI";
}else{
return@"NONE";
}
}