//导入头文件
#import "sys/utsname.h"
//设备型号
+ (NSString *)deviceVersion
{
struct utsname systemInfo;
uname(&systemInfo);
NSString *deviceString = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
//Apple TV
if ([deviceString isEqualToString:@"AppleTV2,1"]) return @"Apple TV 2";
if ([deviceString isEqualToString:@"AppleTV3,1"]||
[deviceString isEqualToString:@"AppleTV3,2"]) return @"Apple TV 3";
if ([deviceString isEqualToString:@"AppleTV5,3"]) return @"Apple TV 4";
if ([deviceString isEqualToString:@"AppleTV6,2"]) return @"Apple TV 4K";
//Apple Watch
if ([deviceString isEqualToString:@"Watch1,1"]||
[deviceString isEqualToString:@"Watch1,2"]) return @"Apple Watch 1";
if ([deviceString isEqualToString:@"Watch2,6"]||
[deviceString isEqualToString:@"Watch2,7"]) return @"Apple Watch Series 1";
if ([deviceString isEqualToString:@"Watch2,3"]||
[deviceString isEqualToString:@"Watch2,4"]) return @"Apple Watch Series 2";
if ([deviceString isEqualToString:@"Watch3,1"]||
[deviceString isEqualToString:@"Watch3,2"]||
[deviceString isEqualToString:@"Watch3,3"]||
[deviceString isEqualToString:@"Watch3,4"]) return @"Apple Watch Series 3";
//iPhone
if ([deviceString isEqualToString:@"iPhone1,1"]) return @"iPhone2G";
if ([deviceString isEqualToString:@"iPhone1,2"]) return @"iPhone3G";
if ([deviceString isEqualToString:@"iPhone2,1"]) return @"iPhone3GS";
if ([deviceString isEqualToString:@"iPhone3,1"]||
[deviceString isEqualToString:@"iPhone3,2"]||
[deviceString isEqualToString:@"iPhone3,3"]) return @"iPhone4";
if ([deviceString isEqualToString:@"iPhone4,1"]) return @"iPhone4S";
if ([deviceString isEqualToString:@"iPhone5,1"]||
[deviceString isEqualToString:@"iPhone5,2"]) return @"iPhone5";
if ([deviceString isEqualToString:@"iPhone5,3"]||
[deviceString isEqualToString:@"iPhone5,4"]) return @"iPhone5C";
if ([deviceString isEqualToString:@"iPhone6,1"]||
[deviceString isEqualToString:@"iPhone6,2"]) return @"iPhone5S";
if ([deviceString isEqualToString:@"iPhone7,2"]) return @"iPhone6";
if ([deviceString isEqualToString:@"iPhone7,1"]) return @"iPhone6 Plus";
if ([deviceString isEqualToString:@"iPhone8,1"]) return @"iPhone6s";
if ([deviceString isEqualToString:@"iPhone8,2"]) return @"iPhone6s Plus";
if ([deviceString isEqualToString:@"iPhone8,4"]) return @"iPhoneSE";
if ([deviceString isEqualToString:@"iPhone9,1"]||
[deviceString isEqualToString:@"iPhone9,3"]) return @"iPhone7";
if ([deviceString isEqualToString:@"iPhone9,2"]||
[deviceString isEqualToString:@"iPhone9,4"]) return @"iPhone7 Plus";
if ([deviceString isEqualToString:@"iPhone10,1"]||
[deviceString isEqualToString:@"iPhone10,4"]) return @"iPhone8";
if ([deviceString isEqualToString:@"iPhone10,2"]||
[deviceString isEqualToString:@"iPhone10,5"]) return @"iPhone8 Plus";
if ([deviceString isEqualToString:@"iPhone10,3"]||
[deviceString isEqualToString:@"iPhone10,6"]) return @"iPhoneX";
//iPod
if ([deviceString isEqualToString:@"iPod1,1"]) return @"iPod Touch1";
if ([deviceString isEqualToString:@"iPod2,1"]) return @"iPod Touch2";
if ([deviceString isEqualToString:@"iPod3,1"]) return @"iPod Touch3";
if ([deviceString isEqualToString:@"iPod4,1"]) return @"iPod Touch4";
if ([deviceString isEqualToString:@"iPod5,1"]) return @"iPod Touch5";
if ([deviceString isEqualToString:@"iPod7,1"]) return @"iPod Touch6";
//iPad
if ([deviceString isEqualToString:@"iPad1,1"]) return @"iPad 1";
if ([deviceString isEqualToString:@"iPad2,1"]||
[deviceString isEqualToString:@"iPad2,2"]||
[deviceString isEqualToString:@"iPad2,3"]||
[deviceString isEqualToString:@"iPad2,4"]) return @"iPad 2";
if ([deviceString isEqualToString:@"iPad3,1"]||
[deviceString isEqualToString:@"iPad3,2"]||
[deviceString isEqualToString:@"iPad3,3"]) return @"iPad 3";
if ([deviceString isEqualToString:@"iPad3,4"]||
[deviceString isEqualToString:@"iPad3,5"]||
[deviceString isEqualToString:@"iPad3,6"]) return @"iPad 4";
if ([deviceString isEqualToString:@"iPad4,1"]||
[deviceString isEqualToString:@"iPad4,2"]||
[deviceString isEqualToString:@"iPad4,3"]) return @"iPad Air";
if ([deviceString isEqualToString:@"iPad5,3"]||
[deviceString isEqualToString:@"iPad5,4"]) return @"iPad Air2";
if ([deviceString isEqualToString:@"iPad6,3"]||
[deviceString isEqualToString:@"iPad6,4"]) return @"iPad Pro (9.7)";
if ([deviceString isEqualToString:@"iPad6,7"]||
[deviceString isEqualToString:@"iPad6,8"]) return @"iPad Pro (12.9)";
if ([deviceString isEqualToString:@"iPad6,11"]||
[deviceString isEqualToString:@"iPad6,12"]) return @"iPad 5";
if ([deviceString isEqualToString:@"iPad7,1"]||
[deviceString isEqualToString:@"iPad7,2"]) return @"iPad Pro 2 (12.9)";
if ([deviceString isEqualToString:@"iPad7,3"]||
[deviceString isEqualToString:@"iPad7,4"]) return @"iPad Pro (10.5)";
//iPad mini
if ([deviceString isEqualToString:@"iPad2,5"]||
[deviceString isEqualToString:@"iPad2,6"]||
[deviceString isEqualToString:@"iPad2,7"]) return @"iPad mini";
if ([deviceString isEqualToString:@"iPad4,4"]||
[deviceString isEqualToString:@"iPad4,5"]||
[deviceString isEqualToString:@"iPad4,6"]) return @"iPad mini2";
if ([deviceString isEqualToString:@"iPad4,7"]||
[deviceString isEqualToString:@"iPad4,8"]||
[deviceString isEqualToString:@"iPad4,9"]) return @"iPad mini3";
if ([deviceString isEqualToString:@"iPad5,1"]||
[deviceString isEqualToString:@"iPad5,2"]) return @"iPad mini4";
//Simulator
if ([deviceString isEqualToString:@"i386"]||
[deviceString isEqualToString:@"x86_64"]) return @"Simulator";
return deviceString?:@"";
}
参考文档:https://www.theiphonewiki.com/wiki/Models