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     }

    效果如下:

  • 相关阅读:
    c网购物车流程图
    NPOI导Excel样式设置
    一个小时快速搭建微信小程序
    ajax实现过程
    JavaWeb结构
    VS常用快捷键
    MVC+三层架构
    JavaScript跨域总结与解决办法[转]
    HTML5是什么?如何鉴定HTML5产品?[转]
    黑盒测试与白盒测试原理
  • 原文地址:https://www.cnblogs.com/kfgcs/p/6378436.html
Copyright © 2011-2022 走看看