#import <sys/utsname.h> //需要导入的头文件
typedef NS_ENUM(NSInteger,kDeviceType) {
iPhone_2G,
iPhone_3G,
iPhone_3GS,
iPhone_4,
iPhone_4S,
iPhone_5,
iPhone_5C,
iPhone_5S,
iPhone_6,
iPhone_6S,
iPhone_6_PLUS,
iPhone_6S_PLUS,
iPhone_SE,
iPhone_7,
iPhone_7_PLUS,
iPod_Touch_1G,
iPod_Touch_2G,
iPod_Touch_3G,
iPod_Touch_4G,
iPod_Touch_5G,
iPad_1G,
iPad_2,
iPad_Mini_1G,
iPad_3,
iPad_4,
iPad_Air,
iPad_Mini_2G,
iPhone_Simulator_32,
iPhone_Simulator_64,
Other_Device,
};
//实现方法
//.h
+ (kDeviceType)currentDevice;
//.m
+ (kDeviceType)currentDevice {
struct utsname systemInfo;
uname(&systemInfo);
NSString *platform = [NSString stringWithCString:systemInfo.machine encoding:NSASCIIStringEncoding];
if ([platform isEqualToString:@"iPhone1,1"]) return iPhone_2G;
if ([platform isEqualToString:@"iPhone1,2"]) return iPhone_3G;
if ([platform isEqualToString:@"iPhone2,1"]) return iPhone_3GS;
if ([platform isEqualToString:@"iPhone3,1"]) return iPhone_4;
if ([platform isEqualToString:@"iPhone3,2"]) return iPhone_4;
if ([platform isEqualToString:@"iPhone3,3"]) return iPhone_4;
if ([platform isEqualToString:@"iPhone4,1"]) return iPhone_4S;
if ([platform isEqualToString:@"iPhone5,1"]) return iPhone_5;
if ([platform isEqualToString:@"iPhone5,2"]) return iPhone_5;
if ([platform isEqualToString:@"iPhone5,3"]) return iPhone_5C;
if ([platform isEqualToString:@"iPhone5,4"]) return iPhone_5C;
if ([platform isEqualToString:@"iPhone6,1"]) return iPhone_5S;
if ([platform isEqualToString:@"iPhone6,2"]) return iPhone_5S;
if ([platform isEqualToString:@"iPhone7,1"]) return iPhone_6;
if ([platform isEqualToString:@"iPhone7,2"]) return iPhone_6_PLUS;
if ([platform isEqualToString:@"iPhone8,1"]) return iPhone_6S;
if ([platform isEqualToString:@"iPhone8,2"]) return iPhone_6S_PLUS;
if ([platform isEqualToString:@"iPhone8,4"]) return iPhone_SE;
if ([platform isEqualToString:@"iPhone9,1"]) return iPhone_7;
if ([platform isEqualToString:@"iPhone9,2"]) return iPhone_7_PLUS;
if ([platform isEqualToString:@"iPod1,1"]) return iPod_Touch_1G;
if ([platform isEqualToString:@"iPod2,1"]) return iPod_Touch_2G;
if ([platform isEqualToString:@"iPod3,1"]) return iPod_Touch_3G;
if ([platform isEqualToString:@"iPod4,1"]) return iPod_Touch_4G;
if ([platform isEqualToString:@"iPod5,1"]) return iPod_Touch_5G;
if ([platform isEqualToString:@"iPad1,1"]) return iPad_1G;
if ([platform isEqualToString:@"iPad2,1"]) return iPad_2;
if ([platform isEqualToString:@"iPad2,2"]) return iPad_2;
if ([platform isEqualToString:@"iPad2,3"]) return iPad_2;
if ([platform isEqualToString:@"iPad2,4"]) return iPad_2;
if ([platform isEqualToString:@"iPad2,5"]) return iPad_Mini_1G;
if ([platform isEqualToString:@"iPad2,6"]) return iPad_Mini_1G;
if ([platform isEqualToString:@"iPad2,7"]) return iPad_Mini_1G;
if ([platform isEqualToString:@"iPad3,1"]) return iPad_3;
if ([platform isEqualToString:@"iPad3,2"]) return iPad_3;
if ([platform isEqualToString:@"iPad3,3"]) return iPad_3;
if ([platform isEqualToString:@"iPad3,4"]) return iPad_4;
if ([platform isEqualToString:@"iPad3,5"]) return iPad_4;
if ([platform isEqualToString:@"iPad3,6"]) return iPad_4;
if ([platform isEqualToString:@"iPad4,1"]) return iPad_Air;
if ([platform isEqualToString:@"iPad4,2"]) return iPad_Air;
if ([platform isEqualToString:@"iPad4,3"]) return iPad_Air;
if ([platform isEqualToString:@"iPad4,4"]) return iPad_Mini_2G;
if ([platform isEqualToString:@"iPad4,5"]) return iPad_Mini_2G;
if ([platform isEqualToString:@"iPad4,6"]) return iPad_Mini_2G;
if ([platform isEqualToString:@"i386"]) return iPhone_Simulator_32;
if ([platform isEqualToString:@"x86_64"]) return iPhone_Simulator_64;
return Other_Device;
}
谢谢阅读!