标签:
在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; }
4.获取设备的UUID:
5.获取当前手机运行的系统以及当前系统的版本
运行效果如下:
有时候我们也需要获取当前App的相关信息,比如当前应用名称, 当前版本号,用于判断是否应该提示用户升级App等.
代码如下:
标签:
原文地址:http://blog.csdn.net/qq_27325349/article/details/51849141