iOS中通过UIDevice获取设备的部分信息

本文介绍如何使用Objective-C通过UIDevice API获取iOS设备的各种属性信息,包括设备名称、型号、系统名称及版本等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

通过[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=hxmMac 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




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

陌影~

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值