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

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




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
常用的手机硬件设备信息包括: 1. 手机型号:手机的型号名称,例如iPhone X、Samsung Galaxy S10等; 2. 操作系统版本:手机所使用的操作系统版本,例如iOS 14、Android 10等; 3. CPU型号和频率:手机的处理器型号和主频,例如Qualcomm Snapdragon 855、Apple A13 Bionic等; 4. 内存大小:手机的内存容量,例如6GB、8GB等; 5. 存储容量:手机的存储空间大小,例如64GB、128GB等; 6. 屏幕分辨率:手机屏幕的分辨率,例如1920x1080、2436x1125等; 7. 相机像素:手机的摄像头像素数,例如1200万像素、4000万像素等; 8. 电池容量:手机的电池容量,例如3000mAh、4000mAh等。 获取这些信息的方法函数在不同的操作系统和编程语言可能略有不同。在Android系统,可以使用android.os.Build类的各种属性获取硬件信息,例如: ``` String model = Build.MODEL; // 手机型号 String osVersion = Build.VERSION.RELEASE; // 操作系统版本 String cpuModel = Build.HARDWARE; // CPU型号 long totalMemory = Runtime.getRuntime().totalMemory(); // 内存总大小 long freeMemory = Runtime.getRuntime().freeMemory(); // 内存可用大小 File path = Environment.getDataDirectory(); // 存储路径 long totalSpace = path.getTotalSpace(); // 存储总大小 long freeSpace = path.getFreeSpace(); // 存储可用大小 DisplayMetrics dm = getResources().getDisplayMetrics(); // 获取屏幕分辨率 int screenWidth = dm.widthPixels; int screenHeight = dm.heightPixels; ``` 在iOS系统,可以使用UIDevice类和NSProcessInfo类的各种属性获取硬件信息,例如: ``` NSString *model = [[UIDevice currentDevice] model]; // 手机型号 NSString *osVersion = [[UIDevice currentDevice] systemVersion]; // 操作系统版本 NSString *cpuModel = [[NSProcessInfo processInfo] processorDescription]; // CPU型号 NSUInteger totalMemory = [NSProcessInfo processInfo].physicalMemory; // 内存总大小 NSUInteger freeMemory = [NSProcessInfo processInfo].availablePhysicalMemory; // 内存可用大小 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *path = [paths objectAtIndex:0]; // 存储路径 NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfFileSystemForPath:path error:nil]; NSNumber *totalSpace = [fileAttributes objectForKey:NSFileSystemSize]; // 存储总大小 NSNumber *freeSpace = [fileAttributes objectForKey:NSFileSystemFreeSize]; // 存储可用大小 CGSize screenSize = [UIScreen mainScreen].bounds.size; // 获取屏幕分辨率 CGFloat screenWidth = screenSize.width; CGFloat screenHeight = screenSize.height; ``` 需要注意的是,某些硬件信息可能需要特殊的权限才能获取,例如相机像素、电池容量等。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Bright1st

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

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

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

打赏作者

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

抵扣说明:

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

余额充值