因为我的项目是unity的,所以把NSString转成char,这个获取方法包含比较新的iPhone XR,XS,XS Max等
具体可以参考https://www.theiphonewiki.com/wiki/Models
char* nmg_util_getDeviceModelName()
{
struct utsname systemInfo;
uname(&systemInfo);
NSString*platform = [NSString stringWithCString: systemInfo.machine encoding:NSASCIIStringEncoding];
NSString *sysDeviceModelName = @"";
if([platform isEqualToString:@"iPhone1,1"]) sysDeviceModelName = @"iPhone 2G";
if([platform isEqualToString:@"iPhone1,2"]) sysDeviceModelName = @"iPhone 3G";
if([platform isEqualToString:@"iPhone2,1"]) sysDeviceModelName = @"iPhone 3GS";
if([platform isEqualToString:@"iPhone3,1"]) sysDeviceModelName = @"iPhone 4";
if([platform isEqualToString:@"iPhone3,2"]) sysDeviceModelName = @"iPhone 4";
if([platform isEqualToString:@"iPhone3,3"]) sysDeviceModelName = @"iPhone 4";
if([platform isEqualToString:@"iPhone4,1"]) sysDeviceModelName = @"iPhone 4S";
if([platform isEqualToString:@"iPhone5,1"]) sysDeviceModelName = @"iPhone 5";
if([platform isEqualToString:@"iPhone5,2"]) sysDeviceModelName = @"iPhone 5";
if([platform isEqualToString:@"iPhone5,3"]) sysDeviceModelName = @"iPhone 5c";
if([platform isEqualToString:@"iPhone5,4"]) sysDeviceModelName = @"iPhone 5c";
if([platform isEqualToString:@"iPhone6,1"]) sysDeviceModelName = @"iPhone 5s";
if([platform isEqualToString:@"iPhone6,2"]) sysDeviceModelName = @"iPhone 5s";
if([platform isEqualToString:@"iPhone7,1"]) sysDeviceModelName = @"iPhone 6 Plus";
if([platform isEqualToString:@"iPhone7,2"]) sysDeviceModelName = @"iPhone 6";
if([platform isEqualToString:@"iPhone8,1"]) sysDeviceModelName = @"iPhone 6s";
if([platform isEqualToString:@"iPhone8,2"]) sysDeviceModelName = @"iPhone 6s Plus";
if([platform isEqualToString:@"iPhone8,4"]) sysDeviceModelName = @"iPhone SE";
if([platform isEqualToString:@"iPhone9,1"]) sysDeviceModelName = @"iPhone 7";
if([platform isEqualToString:@"iPhone9,3"]) sysDeviceModelName = @"iPhone 7";
if([platform isEqualToString:@"iPhone9,2"]) sysDeviceModelName = @"iPhone 7 Plus";
if([platform isEqualToString:@"iPhone9,4"]) sysDeviceModelName = @"iPhone 7 Plus";
if([platform isEqualToString:@"iPhone10,1"]) sysDeviceModelName = @"iPhone 8";
if([platform isEqualToString:@"iPhone10,4"]) sysDeviceModelName = @"iPhone 8";
if([platform isEqualToString:@"iPhone10,2"]) sysDeviceModelName = @"iPhone 8 Plus";
if([platform isEqualToString:@"iPhone10,5"]) sysDeviceModelName = @"iPhone 8 Plus";
if([platform isEqualToString:@"iPhone10,3"]) sysDeviceModelName = @"iPhone X";
if([platform isEqualToString:@"iPhone10,6"]) sysDeviceModelName = @"iPhone X";
if([platform isEqualToString:@"iPhone11,8"]) sysDeviceModelName = @"iPhone XR";
if([platform isEqualToString:@"iPhone11,2"]) sysDeviceModelName = @"iPhone XS";
if([platform isEqualToString:@"iPhone11,6"]) sysDeviceModelName = @"iPhone XS Max";
if([platform isEqualToString:@"iPod1,1"]) sysDeviceModelName = @"iPod Touch 1G";
if([platform isEqualToString:@"iPod2,1"]) sysDeviceModelName = @"iPod Touch 2G";
if([platform isEqualToString:@"iPod3,1"]) sysDeviceModelName = @"iPod Touch 3G";
if([platform isEqualToString:@"iPod4,1"]) sysDeviceModelName = @"iPod Touch 4G";
if([platform isEqualToString:@"iPod5,1"]) sysDeviceModelName = @"iPod Touch 5G";
if([platform isEqualToString:@"iPad1,1"]) sysDeviceModelName = @"iPad 1G";
if([platform isEqualToString:@"iPad2,1"]) sysDeviceModelName = @"iPad 2";
if([platform isEqualToString:@"iPad2,2"]) sysDeviceModelName = @"iPad 2";
if([platform isEqualToString:@"iPad2,3"]) sysDeviceModelName = @"iPad 2";
if([platform isEqualToString:@"iPad2,4"]) sysDeviceModelName = @"iPad 2";
if([platform isEqualToString:@"iPad2,5"]) sysDeviceModelName = @"iPad Mini 1G";
if([platform isEqualToString:@"iPad2,6"]) sysDeviceModelName = @"iPad Mini 1G";
if([platform isEqualToString:@"iPad2,7"]) sysDeviceModelName = @"iPad Mini 1G";
if([platform isEqualToString:@"iPad3,1"]) sysDeviceModelName = @"iPad 3";
if([platform isEqualToString:@"iPad3,2"]) sysDeviceModelName = @"iPad 3";
if([platform isEqualToString:@"iPad3,3"]) sysDeviceModelName = @"iPad 3";
if([platform isEqualToString:@"iPad3,4"]) sysDeviceModelName = @"iPad 4";
if([platform isEqualToString:@"iPad3,5"]) sysDeviceModelName = @"iPad 4";
if([platform isEqualToString:@"iPad3,6"]) sysDeviceModelName = @"iPad 4";
if([platform isEqualToString:@"iPad4,1"]) sysDeviceModelName = @"iPad Air";
if([platform isEqualToString:@"iPad4,2"]) sysDeviceModelName = @"iPad Air";
if([platform isEqualToString:@"iPad4,3"]) sysDeviceModelName = @"iPad Air";
if([platform isEqualToString:@"iPad4,4"]) sysDeviceModelName = @"iPad Mini 2G";
if([platform isEqualToString:@"iPad4,5"]) sysDeviceModelName = @"iPad Mini 2G";
if([platform isEqualToString:@"iPad4,6"]) sysDeviceModelName = @"iPad Mini 2G";
if([platform isEqualToString:@"iPad4,7"]) sysDeviceModelName = @"iPad Mini 3";
if([platform isEqualToString:@"iPad4,8"]) sysDeviceModelName = @"iPad Mini 3";
if([platform isEqualToString:@"iPad4,9"]) sysDeviceModelName = @"iPad Mini 3";
if([platform isEqualToString:@"iPad5,1"]) sysDeviceModelName = @"iPad Mini 4";
if([platform isEqualToString:@"iPad5,2"]) sysDeviceModelName = @"iPad Mini 4";
if([platform isEqualToString:@"iPad5,3"]) sysDeviceModelName = @"iPad Air 2";
if([platform isEqualToString:@"iPad5,4"]) sysDeviceModelName = @"iPad Air 2";
if([platform isEqualToString:@"iPad6,3"]) sysDeviceModelName = @"iPad Pro 9.7";
if([platform isEqualToString:@"iPad6,4"]) sysDeviceModelName = @"iPad Pro 9.7";
if([platform isEqualToString:@"iPad6,7"]) sysDeviceModelName = @"iPad Pro 12.9";
if([platform isEqualToString:@"iPad6,8"]) sysDeviceModelName = @"iPad Pro 12.9";
if([platform isEqualToString:@"iPad6,11"]) sysDeviceModelName = @"iPad 5";
if([platform isEqualToString:@"iPad6,12"]) sysDeviceModelName = @"iPad 5";
if([platform isEqualToString:@"iPad7,1"]) sysDeviceModelName = @"iPad Pro 12.9";
if([platform isEqualToString:@"iPad7,2"]) sysDeviceModelName = @"iPad Pro 12.9";
if([platform isEqualToString:@"iPad7,3"]) sysDeviceModelName = @"iPad Pro 10.5";
if([platform isEqualToString:@"iPad7,4"]) sysDeviceModelName = @"iPad Pro 10.5";
if([platform isEqualToString:@"iPad7,5"]) sysDeviceModelName = @"iPad 6";
if([platform isEqualToString:@"iPad7,6"]) sysDeviceModelName = @"iPad 6";
if([platform isEqualToString:@"iPad8,1"]) sysDeviceModelName = @"iPad Pro 11";
if([platform isEqualToString:@"iPad8,2"]) sysDeviceModelName = @"iPad Pro 11";
if([platform isEqualToString:@"iPad8,3"]) sysDeviceModelName = @"iPad Pro 11";
if([platform isEqualToString:@"iPad8,4"]) sysDeviceModelName = @"iPad Pro 11";
if([platform isEqualToString:@"iPad8,5"]) sysDeviceModelName = @"iPad Pro 12.9";
if([platform isEqualToString:@"iPad8,6"]) sysDeviceModelName = @"iPad Pro 12.9";
if([platform isEqualToString:@"iPad8,7"]) sysDeviceModelName = @"iPad Pro 12.9";
if([platform isEqualToString:@"iPad8,8"]) sysDeviceModelName = @"iPad Pro 12.9";
if([platform isEqualToString:@"iPad11,3"]) sysDeviceModelName = @"iPad Air 3";
if([platform isEqualToString:@"iPad11,4"]) sysDeviceModelName = @"iPad Air 3";
if([platform isEqualToString:@"i386"]) sysDeviceModelName = @"iPhone Simulator";
if([platform isEqualToString:@"x86_64"]) sysDeviceModelName = @"iPhone Simulator";
NSLog(@"[NMGUtilUnity] nmg_util_getDeviceModelName:%@",sysDeviceModelName);
return (char*)[sysDeviceModelName UTF8String];
}