Fork me on GitHub

iOS设备型号 2018最新统计

最近发现项目里设备型号没有匹配最近新发布的几款设备,于是去官网查看了下。

所有设备型号对应的官网地址:

官网地址: https://www.theiphonewiki.com/wiki/Models

来点更加暴力的,直接上代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// 记得导入头文件
#import <sys/sysctl.h>

// 获取具体的设备型号(不包含Watch和TV)
+ (NSString *)deviceModel {

int mib[2];
size_t len;
char *machine;

mib[0] = CTL_HW;
mib[1] = HW_MACHINE;
sysctl(mib, 2, NULL, &len, NULL, 0);
machine = malloc(len);
sysctl(mib, 2, machine, &len, NULL, 0);

NSString *platform = [NSString stringWithCString:machine encoding:NSASCIIStringEncoding];
free(machine);

// MARK: - Simulator
if ([platform isEqualToString:@"i386"] || [platform isEqualToString:@"x86_64"]) { return @"iPhoneSimulator"; }

// MARK: - iPhone
if ([platform isEqualToString:@"iPhone1,1"]) { return @"iPhone2G"; }
if ([platform isEqualToString:@"iPhone1,2"]) { return @"iPhone3G"; }
if ([platform isEqualToString:@"iPhone2,1"]) { return @"iPhone3GS"; }
if ([platform isEqualToString:@"iPhone3,1"] || [platform isEqualToString:@"iPhone3,2"] || [platform isEqualToString:@"iPhone3,3"]) { return @"iPhone4"; }
if ([platform isEqualToString:@"iPhone4,1"]) { return @"iPhone4S"; }
if ([platform isEqualToString:@"iPhone5,1"] || [platform isEqualToString:@"iPhone5,2"]) { return @"iPhone5"; }
if ([platform isEqualToString:@"iPhone5,3"] || [platform isEqualToString:@"iPhone5,4"]) { return @"iPhone5c"; }
if ([platform isEqualToString:@"iPhone6,1"] || [platform isEqualToString:@"iPhone6,2"]) { return @"iPhone5s"; }

if ([platform isEqualToString:@"iPhone7,2"]) { return @"iPhone6"; }
if ([platform isEqualToString:@"iPhone7,1"]) { return @"iPhone6Plus"; }
if ([platform isEqualToString:@"iPhone8,1"]) { return @"iPhone6s"; }
if ([platform isEqualToString:@"iPhone8,2"]) { return @"iPhone6sPlus"; }
if ([platform isEqualToString:@"iPhone8,3"] || [platform isEqualToString:@"iPhone8,4"]) { return @"iPhoneSE"; }
if ([platform isEqualToString:@"iPhone9,1"] || [platform isEqualToString:@"iPhone9,3"]) { return @"iPhone7"; }
if ([platform isEqualToString:@"iPhone9,2"] || [platform isEqualToString:@"iPhone9,4"]) { return @"iPhone7Plus"; }
if ([platform isEqualToString:@"iPhone10,1"] || [platform isEqualToString:@"iPhone10,4"]) { return @"iPhone8"; }
if ([platform isEqualToString:@"iPhone10,2"] || [platform isEqualToString:@"iPhone10,5"]) { return @"iPhone8Plus"; }
if ([platform isEqualToString:@"iPhone10,3"] || [platform isEqualToString:@"iPhone10,6"]) { return @"iPhoneX"; }

// MARK: - iPod Touch
if ([platform isEqualToString:@"iPod1,1"]) { return @"iPodTouch"; }
if ([platform isEqualToString:@"iPod2,1"]) { return @"iPodTouch2G"; }
if ([platform isEqualToString:@"iPod3,1"]) { return @"iPodTouch3G"; }
if ([platform isEqualToString:@"iPod4,1"]) { return @"iPodTouch4G"; }
if ([platform isEqualToString:@"iPod5,1"]) { return @"iPodTouch5G"; }
if ([platform isEqualToString:@"iPod7,1"]) { return @"iPodTouch6G"; }

// MARK: - iPad
if ([platform isEqualToString:@"iPad1,1"]) { return @"iPad"; }
if ([platform isEqualToString:@"iPad2,1"] || [platform isEqualToString:@"iPad2,2"] || [platform isEqualToString:@"iPad2,3"] || [platform isEqualToString:@"iPad2,4"]) { return @"iPad2"; }
if ([platform isEqualToString:@"iPad3,1"] || [platform isEqualToString:@"iPad3,2"] || [platform isEqualToString:@"iPad3,3"]) { return @"iPad3"; }
if ([platform isEqualToString:@"iPad3,4"] || [platform isEqualToString:@"iPad3,5"] || [platform isEqualToString:@"iPad3,6"]) { return @"iPad4"; }

// MARK: - iPad Air
if ([platform isEqualToString:@"iPad4,1"] || [platform isEqualToString:@"iPad4,2"] || [platform isEqualToString:@"iPad4,3"]) { return @"iPadAir"; }
if ([platform isEqualToString:@"iPad5,3"] || [platform isEqualToString:@"iPad5,4"]) { return @"iPadAir2"; }
if ([platform isEqualToString:@"iPad6,11"] || [platform isEqualToString:@"iPad6,12"]) return @"iPadAir3";

// MARK: - iPad Pro
if ([platform isEqualToString:@"iPad6,7"] || [platform isEqualToString:@"iPad6,8"]) { return @"iPad Pro 12.9-inch"; }
if ([platform isEqualToString:@"iPad6,3"] || [platform isEqualToString:@"iPad6,4"]) { return @"iPad Pro iPad 9.7-inch"; }
if ([platform isEqualToString:@"iPad7,1"] || [platform isEqualToString:@"iPad7,2"]) { return @"iPad Pro 12.9-inch 2"; }
if ([platform isEqualToString:@"iPad7,3"] || [platform isEqualToString:@"iPad7,4"]) { return @"iPad Pro 10.5-inch"; }

// MARK: - iPad mini
if ([platform isEqualToString:@"iPad2,5"] || [platform isEqualToString:@"iPad2,6"] || [platform isEqualToString:@"iPad2,7"]) { return @"iPadmini1G"; }
if ([platform isEqualToString:@"iPad4,4"] || [platform isEqualToString:@"iPad4,5"] || [platform isEqualToString:@"iPad4,6"]) { return @"iPadmini2"; }
if ([platform isEqualToString:@"iPad4,7"] || [platform isEqualToString:@"iPad4,8"] || [platform isEqualToString:@"iPad4,9"]) { return @"iPadmini3"; }
if ([platform isEqualToString:@"iPad5,1"] || [platform isEqualToString:@"iPad5,2"]) { return @"iPadmini4"; }

return platform;
}
------------- 本文结束感谢您的阅读 -------------