码迷,mamicode.com
首页 > 移动开发 > 详细

iOS 设备信息

时间:2016-07-07 11:05:30      阅读:201      评论:0      收藏:0      [点我收藏+]

标签:

在iOS开发中,有时候我们需要使用跟设备相关的一些信息,下面就详细介绍一下设备相关信息:

1.获取当前设备所有者名称:

技术分享

技术分享

2.获取设备的类别,是iPhone,iPod,还是iPad

技术分享

这里要获取iPhone的具体类型,要有如下代码:

- (NSString *)deviceString {

    // 需要#import "sys/utsname.h"
    struct utsname systeminfo;
    uname(&systeminfo);
    
    NSString *deviceString = [NSString stringWithCString:systeminfo.machine encoding:NSUTF8StringEncoding];
    
    //iPhone
    if ([deviceString isEqualToString:@"iPhone1,1"]) return @"iPhone 1G";
    if ([deviceString isEqualToString:@"iPhone1,2"]) return @"iPhone 3G";
    if ([deviceString isEqualToString:@"iPhone2,1"]) return @"iPhone 3GS";
    if ([deviceString isEqualToString:@"iPhone3,1"]) return @"iPhone 4";
    if ([deviceString isEqualToString:@"iPhone3,2"]) return @"Verizon iPhone 4";
    if ([deviceString isEqualToString:@"iPhone4,1"]) return @"iPhone 4S";
    
    if ([deviceString isEqualToString:@"iPhone5,1"]) return @"iPhone 5";
    if ([deviceString isEqualToString:@"iPhone5,2"]) return @"iPhone 5";
    if ([deviceString isEqualToString:@"iPhone5,3"]) return @"iPhone 5C";
    if ([deviceString isEqualToString:@"iPhone5,4"]) return @"iPhone 5C";
    
    if ([deviceString isEqualToString:@"iPhone6,1"]) return @"iPhone 5S";
    if ([deviceString isEqualToString:@"iPhone6,2"]) return @"iPhone 5S";
    
    if ([deviceString isEqualToString:@"iPhone7,1"]) return @"iPhone 6 Plus";
    if ([deviceString isEqualToString:@"iPhone7,2"]) return @"iPhone 6";
    
    if ([deviceString isEqualToString:@"iPhone8,1"]) return @"iPhone 6s";
    if ([deviceString isEqualToString:@"iPhone8,2"]) return @"iPhone 6s Plus";
    
    
    //iPod
    if ([deviceString isEqualToString:@"iPod1,1"]) return @"iPod Touch 1G";
    if ([deviceString isEqualToString:@"iPod2,1"]) return @"iPod Touch 2G";
    if ([deviceString isEqualToString:@"iPod3,1"]) return @"iPod Touch 3G";
    if ([deviceString isEqualToString:@"iPod4,1"]) return @"iPod Touch 4G";
    if ([deviceString isEqualToString:@"iPod5,1"]) return @"iPod Touch 5G";

    return nil;
}

3.设备本地化类别:

技术分享


4.获取设备的UUID:

技术分享


5.获取当前手机运行的系统以及当前系统的版本

技术分享技术分享


运行效果如下:

技术分享


有时候我们也需要获取当前App的相关信息,比如当前应用名称, 当前版本号,用于判断是否应该提示用户升级App等.

 代码如下:

技术分享

iOS 设备信息

标签:

原文地址:http://blog.csdn.net/qq_27325349/article/details/51849141

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!