通过[UIDevice currentDevice] 可以获取到当前设备对象,通过KVC获取设备的属性信息,主要属性有:
name//设备名称
model//模型
localizedModel//本地化模型
systemName//系统名称
systemVersion//系统版本
orientation //设备方向
batteryMonitoringEnabled//电池监听是否可用
batteryState//电池状态
batteryLevel//电池电量
proximityMonitoringEnabled//距离感应器监听是否可用
proximityState//距离感应器状态
multitaskingSupported//是否支持多任务
NSString * name = [[UIDevice currentDevice] valueForKey:@"name"];
NSString * model = [[UIDevice currentDevice] valueForKey:@"model"];
NSString * localizedModel = [[UIDevice currentDevice] valueForKey:@"localizedModel"];
NSString * systemName = [[UIDevice currentDevice] valueForKey:@"systemName"];
NSString * systemVersion = [[UIDevice currentDevice] valueForKey:@"systemVersion"];
UIDeviceOrientation orientation = [[[UIDevice currentDevice] valueForKey:@"orientation"] intValue];
BOOL batteryMonitoringEnabled = [[[UIDevice currentDevice] valueForKey:@"batteryMonitoringEnabled"] boolValue];
UIDeviceBatteryState batteryState = [[[UIDevice currentDevice] valueForKey:@"batteryState"] intValue];
float batteryLevel = [[[UIDevice currentDevice] valueForKey:@"batteryLevel"] floatValue];
BOOL proximityMonitoringEnabled = [[[UIDevice currentDevice] valueForKey:@"proximityMonitoringEnabled"] intValue];
BOOL proximityState = [[[UIDevice currentDevice] valueForKey:@"proximityState"] intValue];
BOOL multitaskingSupported = [[[UIDevice currentDevice] valueForKey:@"multitaskingSupported"] intValue];
NSLog(@"\nname=%@, \nmodel=%@, \nlocalizedModel=%@, \nsystemName=%@, \nsystemVersion=%@, \norientation=%ld, \nbatteryMonitoringEnabled=%d, \nbatteryState=%ld, \nbatteryLevel=%f, \nproximityMonitoringEnabled=%d, \nproximityState=%d, \nmultitaskingSupported=%d", name, model, localizedModel, systemName, systemVersion, (long)orientation, batteryMonitoringEnabled, (long)batteryState, batteryLevel, proximityMonitoringEnabled, proximityState, multitaskingSupported);
打印出的结果如下:
name=hxm的Mac mini,
model=iPhone,
localizedModel=iPhone,
systemName=iOS,
systemVersion=10.2,
orientation=0,
batteryMonitoringEnabled=0,
batteryState=0,
batteryLevel=-1.000000,
proximityMonitoringEnabled=0,
proximityState=0,
multitaskingSupported=1