如何判断当前iPhone的机型,iPhone代号对应关系

不多说,直接上代码,拿去用即可!!别问我是怎么知道,如果你有这么多手机的话你也可以去测。

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
+ (NSString *)deviceString
{
????struct utsname systemInfo;
????uname(&systemInfo);
????NSString *deviceString = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
?????
????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 @"iPhone 4";
????if ([deviceString isEqualToString:@"iPhone3,3"])??? return @"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,2"])??? return @"iPhone 6";
????if ([deviceString isEqualToString:@"iPhone7,1"])??? return @"iPhone 6 Plus";
????if ([deviceString isEqualToString:@"i386"])???????? return @"Simulator";
????if ([deviceString isEqualToString:@"x86_64"])?????? return @"Simulator";
????else return @"Unknown Device";
????return deviceString;
}

PS:要导入头文件 #import “sys/utsname.h” , 不然会找不到 utsname systemInfo

Leave a Reply