zoukankan      html  css  js  c++  java
  • 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     }

    效果如下:

  • 相关阅读:
    sublime text3快速编辑选中多行
    sublime text3实现多行快速编辑Ctrl+E或者Tab
    WPF集合控件实现分隔符(ItemsControl Separator)
    WPF的ListView控件自定义布局用法实例
    ASP.NET MVC4+BootStrap 实战(一)
    wpf 获取datagrid 模板列中的控件
    WPF之DataGrid篇:DataGridComboBoxColumn
    WPF DataGrid 样式分享
    WPF之DataTemplateSelector技巧
    【WPF】ComboBox:根据绑定选取、设置固定集合中的值
  • 原文地址:https://www.cnblogs.com/kfgcs/p/6378436.html
Copyright © 2011-2022 走看看