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     }

效果如下:

 

posted @ 2017-02-16 15:20  福泽小院  阅读(1403)  评论(0编辑  收藏  举报