设备信息

2017-07-21  本文已影响11人  一笔春秋

1、获取运营商的信息

1)需要先导入头文件 

CoreTelephony/CTCarrier.h、CoreTelephony/CTTelephonyNetworkInfo.h

2)创建对象

CCTelephonyNetworkInfo *info =[[CTTelephonyNetworkInfo alloc] init];

CTCarrier *carrier = [info subscriberCellularProvider];

NSString *mCarrier = [NSString stringWithFormat:@"%@",[carrier carrierName]];

3)获取当前网络的类型

NSString*mConnectType = [[NSString alloc] initWithFormat:@"%@",info.currentRadioAccessTechnology];

类型:

CTRadioAccessTechnologyGPRS//介于2G和3G之间,也叫2.5G ,过度技术CTRadioAccessTechnologyEdge//EDGE为GPRS到第三代移动通信的过渡,EDGE俗称2.75GCTRadioAccessTechnologyWCDMA

CTRadioAccessTechnologyHSDPA//亦称为3.5G(3?G)CTRadioAccessTechnologyHSUPA//3G到4G的过度技术CTRadioAccessTechnologyCDMA1x//3GCTRadioAccessTechnologyCDMAEVDORev0//3G标准CTRadioAccessTechnologyCDMAEVDORevA

CTRadioAccessTechnologyCDMAEVDORevB

CTRadioAccessTechnologyeHRPD//电信使用的一种3G到4G的演进技术, 3.75GCTRadioAccessTechnologyLTE//接近4G

2、获取电池的相关信息

//获取电池当前的状态,共有4种状态

-(NSString*) getBatteryState {

UIDevice *device = [UIDevice currentDevice];

if(device.batteryState == UIDeviceBatteryStateUnknown) 

{

    return@"UnKnow";

}

else if(device.batteryState== UIDeviceBatteryStateUnplugged)

{

    return@"Unplugged";

}

else if(device.batteryState== UIDeviceBatteryStateCharging)

{

    return@"Charging";

}

else if(device.batteryState== UIDeviceBatteryStateFull)

{

    return@"Full";

}

return   nil;

}

//获取电量的等级,0.00~1.00

-(float) getBatteryLevel 

{

return    [UIDevice currentDevice].batteryLevel;

}

//打开对电量和电池状态的监控,类似定时器的功能

-(void) didLoad

{

[[UIDevice currentDevice] setBatteryMonitoringEnable:YES];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getBatteryInfo:) name:UIDeviceBatteryStateDidChangeNotification  object:nil];

[[NSNotificationCenter defaultCenter] addObserver:selfselector:@selector(getBatteryInfo:) name:UIDeviceBatteryLevelDidChangeNotification object:nil];

[NSTimer scheduledTimerWithTimeInterval:0.5f target:self selector:@selector(getBatteryInfo:) userInfo:nilrepeats:YES];

}

上一篇下一篇

猜你喜欢

热点阅读