UIDevice之获取设备信息

UIDevice这个类提供了一个代表当前设备的一个实例。从这个实例中可以获得有关设备如指定名称,信息设备模型,和操作系统名称和版本。UIDevice直接继承自NSObject。

UIDevice类可以提供了多种属性、类函数及状态通知,帮助我们全方位了解设备状况。从检测电池电量到定位设备与临近感应,UIDevice所做的工作就是为应用程序提供用户及设备的一些信息。

UIDevice类还能够收集关于设备的各种具体细节,例如机型及iOS版本等。其中大部分属性都对开发工作具有积极的辅助作用。

 

我们可以获取设备的信息通过如下方法:

代码如下:

 1     NSArray *array=[[NSArray alloc]initWithObjects:@"设备名称:",@"系统名称:",@"系统版本号:",@"设备模式:",@"本地设备模式:",nil];
 2     //获取当前设备的:设备名称,系统名称,系统版本号,设备模式,本地设备模式,获取之后装进数组。
 3     NSArray *deviceArray=[[NSArray alloc]initWithObjects:[[UIDevice currentDevice]name],[[UIDevice currentDevice] systemName],[[UIDevice currentDevice]systemVersion],[[UIDevice currentDevice]model],[[UIDevice currentDevice]localizedModel], nil];
 4     for (int i=0; i<5; i++) {
 5         UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(0, 50+i*50,[UIScreen mainScreen].bounds.size.width/2-50,50)];
 6         label.text=[array objectAtIndex:i];
 7         label.textAlignment=NSTextAlignmentRight;
 8         [self.view addSubview:label];
 9         UILabel *deviceLabel=[[UILabel alloc]initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width/2-40, 50+i*50,[UIScreen mainScreen].bounds.size.width/2-50,50)];
10         deviceLabel.text=[deviceArray objectAtIndex:i];
11         [self.view addSubview:deviceLabel];
12         
13     }

效果如下:

 

转载于:https://www.cnblogs.com/kfgcs/p/6378436.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值