根据设备的型号model来判断
#import
#import
- (BOOL)isiPhoneX {
static BOOL isiPhoneX = NO;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
#if TARGET_IPHONE_SIMULATOR
// 获取模拟器所对应的 device model
NSString *model = NSProcessInfo.processInfo.environment[@"SIMULATOR_MODEL_IDENTIFIER"];
#else
// 获取真机设备的 device model
struct utsname systemInfo;
uname(&systemInfo);
NSString *model = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
#endif
// 判断 device model 是否为 "iPhone10,3" 和 "iPhone10,6" 或者以 "iPhone11," 开头
// 如果是,就认为是 iPhone X
isiPhoneX = [model isEqualToString:@"iPhone10,3"] || [model isEqualToString:@"iPhone10,6"] || [model hasPrefix:@"iPhone11,"]||[model isEqualToString:@"iPhone12,1"]||[model isEqualToString:@"iPhone12,3"]||[model isEqualToString:@"iPhone12,5"];
});
return isiPhoneX;
}
判断设备型号方法:
ipad可能不全,iPhone已完善
+ (NSString *)getCurrentDeviceModel{
struct utsname systemInfo;
uname(&systemInfo);
NSString *deviceModel = @"iPhone";
deviceModel = [NSString stringWithCString:systemInfo.machine encoding:NSASCIIStringEncoding];
if ([deviceModel isEqualToString:@"iPhone3,1"]) return @"iPhone 4";
else if ([deviceModel isEqualToString:@"iPhone3,2"]) return @"iPhone4";
else if ([deviceModel isEqualToString:@"iPhone3,3"]) return @"iPhone4";
else if ([deviceModel isEqualToString:@"iPhone4,1"]) return @"iPhone4S";
else if ([deviceModel isEqualToString:@"iPhone5,1"]) return @"iPhone5";
else if ([deviceModel isEqualToString:@"iPhone5,2"]) return @"iPhone5 (GSM+CDMA)";
else if ([deviceModel isEqualToString:@"iPhone5,3"]) return @"iPhone5c (GSM)";
else if ([deviceModel isEqualToString:@"iPhone5,4"]) return @"iPhone5c(GSM+CDMA)";
else if ([deviceModel isEqualToString:@"iPhone6,1"]) return @"iPhone5s(GSM)";
else if ([deviceModel isEqualToString:@"iPhone6,2"]) return @"iPhone5s(GSM+CDMA)";
else if ([deviceModel isEqualToString:@"iPhone7,1"]) return @"iPhone6Plus";
else if ([deviceModel isEqualToString:@"iPhone7,2"]) return @"iPhone6";
else if ([deviceModel isEqualToString:@"iPhone8,1"]) return @"iPhone6s";
else if ([deviceModel isEqualToString:@"iPhone8,2"]) return @"iPhone6sPlus";
else if ([deviceModel isEqualToString:@"iPhone8,4"]) return @"iPhoneSE";
// 日行两款手机型号均为日本独占,可能使用索尼FeliCa支付方案而不是苹果支付
else if ([deviceModel isEqualToString:@"iPhone9,1"]) return @"iPhone7";
else if ([deviceModel isEqualToString:@"iPhone9,2"]) return @"iPhone7Plus";
else if ([deviceModel isEqualToString:@"iPhone9,3"]) return @"iPhone7";
else if ([deviceModel isEqualToString:@"iPhone9,4"]) return @"iPhone7Plus";
else if ([deviceModel isEqualToString:@"iPhone10,1"]) return @"iPhone_8";
else if ([deviceModel isEqualToString:@"iPhone10,4"]) return @"iPhone_8";
else if ([deviceModel isEqualToString:@"iPhone10,2"]) return @"iPhone_8_Plus";
else if ([deviceModel isEqualToString:@"iPhone10,5"]) return @"iPhone_8_Plus";
else if ([deviceModel isEqualToString:@"iPhone10,3"]) return @"iPhoneX";
else if ([deviceModel isEqualToString:@"iPhone10,6"]) return @"iPhoneX";
else if ([deviceModel isEqualToString:@"iPhone11,8"]) return @"iPhoneXR";
else if ([deviceModel isEqualToString:@"iPhone11,2"]) return @"iPhoneXS";
else if ([deviceModel isEqualToString:@"iPhone11,6"]) return @"iPhoneXSMax";
else if ([deviceModel isEqualToString:@"iPhone11,4"]) return @"iPhoneXSMax";
else if ([deviceModel isEqualToString:@"iPhone12,1"]) return @"iPhone 11";
else if ([deviceModel isEqualToString:@"iPhone12,3"]) return @"iPhone11Pro";
else if ([deviceModel isEqualToString:@"iPhone12,5"]) return @"iPhone 11 Pro Max";
else if ([deviceModel isEqualToString:@"iPhone12,8"]) return @"iPhoneSE(2nd generation)";
else if ([deviceModel isEqualToString:@"iPhone13,1"]) return @"iPhone 12 mini";
else if ([deviceModel isEqualToString:@"iPhone13,2"]) return @"iPhone 12";
else if ([deviceModel isEqualToString:@"iPhone13,3"]) return @"iPhone 12 Pro";
else if ([deviceModel isEqualToString:@"iPhone13,4"]) return @"iPhone 12 Pro Max";
else if ([deviceModel isEqualToString:@"iPod1,1"]) return @"iPodTouch1G";
else if ([deviceModel isEqualToString:@"iPod2,1"]) return @"iPodTouch2G";
else if ([deviceModel isEqualToString:@"iPod3,1"]) return @"iPodTouch3G";
else if ([deviceModel isEqualToString:@"iPod4,1"]) return @"iPodTouch4G";
else if ([deviceModel isEqualToString:@"iPod5,1"]) return @"iPodTouch(5 Gen)";
else if ([deviceModel isEqualToString:@"iPad1,1"]) return @"iPad";
else if ([deviceModel isEqualToString:@"iPad1,2"]) return @"iPad3G";
else if ([deviceModel isEqualToString:@"iPad2,1"]) return @"iPad2(WiFi)";
else if ([deviceModel isEqualToString:@"iPad2,2"]) return @"iPad2";
else if ([deviceModel isEqualToString:@"iPad2,3"]) return @"iPad2(CDMA)";
else if ([deviceModel isEqualToString:@"iPad2,4"]) return @"iPad2";
else if ([deviceModel isEqualToString:@"iPad2,5"]) return @"iPadMini(WiFi)";
else if ([deviceModel isEqualToString:@"iPad2,6"]) return @"iPadMini";
else if ([deviceModel isEqualToString:@"iPad2,7"]) return @"iPad Mini (GSM+CDMA)";
else if ([deviceModel isEqualToString:@"iPad3,1"]) return @"iPad 3 (WiFi)";
else if ([deviceModel isEqualToString:@"iPad3,2"]) return @"iPad 3 (GSM+CDMA)";
else if ([deviceModel isEqualToString:@"iPad3,3"]) return @"iPad 3";
else if ([deviceModel isEqualToString:@"iPad3,4"]) return @"iPad 4 (WiFi)";
else if ([deviceModel isEqualToString:@"iPad3,5"]) return @"iPad 4";
else if ([deviceModel isEqualToString:@"iPad3,6"]) return @"iPad 4 (GSM+CDMA)";
else if ([deviceModel isEqualToString:@"iPad4,1"]) return @"iPad Air (WiFi)";
else if ([deviceModel isEqualToString:@"iPad4,2"]) return @"iPad Air (Cellular)";
else if ([deviceModel isEqualToString:@"iPad4,4"]) return @"iPad Mini 2 (WiFi)";
else if ([deviceModel isEqualToString:@"iPad4,5"]) return @"iPad Mini 2 (Cellular)";
else if ([deviceModel isEqualToString:@"iPad4,6"]) return @"iPad Mini 2";
else if ([deviceModel isEqualToString:@"iPad4,7"]) return @"iPad Mini 3";
else if ([deviceModel isEqualToString:@"iPad4,8"]) return @"iPad Mini 3";
else if ([deviceModel isEqualToString:@"iPad4,9"]) return @"iPad Mini 3";
else if ([deviceModel isEqualToString:@"iPad5,1"]) return @"iPad Mini 4 (WiFi)";
else if ([deviceModel isEqualToString:@"iPad5,2"]) return @"iPad Mini 4 (LTE)";
else if ([deviceModel isEqualToString:@"iPad5,3"]) return @"iPad Air 2";
else if ([deviceModel isEqualToString:@"iPad5,4"]) return @"iPad Air 2";
else if ([deviceModel isEqualToString:@"iPad6,3"]) return @"iPad Pro 9.7";
else if ([deviceModel isEqualToString:@"iPad6,4"]) return @"iPad Pro 9.7";
else if ([deviceModel isEqualToString:@"iPad6,7"]) return @"iPad Pro 12.9";
else if ([deviceModel isEqualToString:@"iPad6,8"]) return @"iPad Pro 12.9";
else if ([deviceModel isEqualToString:@"AppleTV2,1"]) return @"Apple TV 2";
else if ([deviceModel isEqualToString:@"AppleTV3,1"]) return @"Apple TV 3";
else if ([deviceModel isEqualToString:@"AppleTV3,2"]) return @"Apple TV 3";
else if ([deviceModel isEqualToString:@"AppleTV5,3"]) return @"Apple TV 4";
else if ([deviceModel isEqualToString:@"i386"]) return @"Simulator";
else if ([deviceModel isEqualToString:@"x86_64"]) return @"Simulator";
return deviceModel;
}
要添加全请参考链接自己添加
https://www.theiphonewiki.com/wiki/Models