NSString *wb_device_models() {
NSString *hardware = wb_hardware_machine();
/** iPhone Simulator */
if ([hardware hasSuffix:@"86"] ||
[hardware isEqual:@"x86_64"]) return @"Simulator";
if ([hardware hasPrefix:@"iPhone"]) {
/** iPhone */
if ([hardware isEqualToString:@"iPhone1,1"]) return @"iPhone";
if ([hardware isEqualToString:@"iPhone1,2"]) return @"iPhone 3G";
if ([hardware isEqualToString:@"iPhone2,1"]) return @"iPhone 3GS";
/** iPhone 4 */
if ([hardware isEqualToString:@"iPhone3.1"] ||
[hardware isEqualToString:@"iPhone3,2"]) return @"iPhone 4 GSM";
if ([hardware isEqualToString:@"iPhone3,3"]) return @"iPhone 4 CDMA";
/** iPhone 4S */
if ([hardware isEqualToString:@"iPhone4,1"]) return @"iPhone 4S";
/** iPhone 5 */
if ([hardware isEqualToString:@"iPhone5,1"]) return @"iPhone 5 GSM";
if ([hardware isEqualToString:@"iPhone5,2"]) return @"iPhone 5 Global";
/** iPhone 5C */
if ([hardware isEqualToString:@"iPhone5,3"]) return @"iPhone 5C GSM";
if ([hardware isEqualToString:@"iPhone5,4"]) return @"iPhone 5C Global";
/** iPhone 5S */
if ([hardware isEqualToString:@"iPhone6,1"]) return @"iPhone 5S GSM";
if ([hardware isEqualToString:@"iPhone6,2"]) return @"iPhone 5S Global";
/** iPhone 6 */
if ([hardware isEqualToString:@"iPhone7,1"]) return @"iPhone 6 Plus";
if ([hardware isEqualToString:@"iPhone7,2"]) return @"iPhone 6";
/** iPhone 6S */
if ([hardware isEqualToString:@"iPhone8,1"]) return @"iPhone 6S";
if ([hardware isEqualToString:@"iPhone8,2"]) return @"iPhone 6S Plus";
/** iPhone SE */
if ([hardware isEqualToString:@"iPhone8,4"]) return @"iPhone SE";
/** iPhone 7 */
if ([hardware isEqualToString:@"iPhone9,1"] ||
[hardware isEqualToString:@"iPhone9,3"]) return @"iPhone 7";
if ([hardware isEqualToString:@"iPhone9,2"] ||
[hardware isEqualToString:@"iPhone9,4"]) return @"iPhone 7 Plus";
/** iPhone 8 */
if ([hardware isEqualToString:@"iPhone10,1"] ||
[hardware isEqualToString:@"iPhone10,4"]) return @"iPhone 8";
if ([hardware isEqualToString:@"iPhone10,2"] ||
[hardware isEqualToString:@"iPhone10,5"]) return @"iPhone 8 Plus";
if ([hardware isEqualToString:@"iPhone10,3"] ||
[hardware isEqualToString:@"iPhone10,6"]) return @"iPhone X";
if ([hardware isEqualToString:@"iPhone11,2"]) return @"iPhone XS";
if ([hardware isEqualToString:@"iPhone11,4"] ||
[hardware isEqualToString:@"iPhone11,6"]) return @"iPhone XS Max";
if ([hardware isEqualToString:@"iPhone11,8"]) return @"iPhone XR";
/** iPhone 11 */
if ([hardware isEqualToString:@"iPhone12,1"]) return @"iPhone 11";
if ([hardware isEqualToString:@"iPhone12,3"]) return @"iPhone 11 Pro";
if ([hardware isEqualToString:@"iPhone12,5"]) return @"iPhone 11 Pro Max";
}
else if ([hardware hasPrefix:@"iPod"]) {
/** iPod Touch */
if ([hardware isEqualToString:@"iPod1,1"]) return @"iPod touch";
if ([hardware isEqualToString:@"iPod2,1"]) return @"iPod touch 2G";
if ([hardware isEqualToString:@"iPod3,1"]) return @"iPod touch 3G";
if ([hardware isEqualToString:@"iPod4,1"]) return @"iPod touch 4G";
if ([hardware isEqualToString:@"iPod5,1"]) return @"iPod touch 5G";
if ([hardware isEqualToString:@"iPod7,1"]) return @"iPod touch 6G";
if ([hardware isEqualToString:@"iPod9,1"]) return @"iPod touch 7G";
}
else if ([hardware hasPrefix:@"iPad"]) {
/** iPad */
if ([hardware isEqualToString:@"iPad1,1"]) return @"iPad";
/** iPad 2 */
if ([hardware isEqualToString:@"iPad2,1"]) return @"iPad 2 Wi-Fi";
if ([hardware isEqualToString:@"iPad2,2"]) return @"iPad 2 GSM";
if ([hardware isEqualToString:@"iPad2,3"]) return @"iPad 2 CDMA";
if ([hardware isEqualToString:@"iPad2,4"]) return @"iPad 2 Wi-Fi";
/** iPad 3 */
if ([hardware isEqualToString:@"iPad3,1"]) return @"iPad 3 Wi-Fi";
if ([hardware isEqualToString:@"iPad3,2"]) return @"iPad 3 Wi-Fi + Cellular (VZ)";
if ([hardware isEqualToString:@"iPad3,3"]) return @"iPad 3 Wi-Fi + Cellular";
/** iPad 4 */
if ([hardware isEqualToString:@"iPad3,4"]) return @"iPad 4 Wi-Fi";
if ([hardware isEqualToString:@"iPad3,5"]) return @"iPad 4 Wi-Fi + Cellular";
if ([hardware isEqualToString:@"iPad3,6"]) return @"iPad 4 Wi-Fi + Cellular (MM)";
/** iPad Air */
if ([hardware isEqualToString:@"iPad4,1"]) return @"iPad Air Wi-Fi";
if ([hardware isEqualToString:@"iPad4,2"]) return @"iPad Air Wi-Fi + Cellular";
if ([hardware isEqualToString:@"iPad4,3"]) return @"iPad Air Wi-Fi + Cellular (TD-LTE)";
/** iPad Air 2 */
if ([hardware isEqualToString:@"iPad5,3"]) return @"iPad Air 2 Wi-Fi";
if ([hardware isEqualToString:@"iPad5,4"]) return @"iPad Air 2 Wi-Fi + Cellular";
/** iPad Air 3 */
if ([hardware isEqualToString:@"iPad11,3"]) return @"iPad Air 3 Wi-Fi";
if ([hardware isEqualToString:@"iPad11,4"]) return @"iPad Air 3 Wi-Fi + Cellular";
/** iPad (9.7 inch - 5th generation) */
if ([hardware isEqualToString:@"iPad6,11"]) return @"iPad 5 Wi-Fi";
if ([hardware isEqualToString:@"iPad6,12"]) return @"iPad 5 Wi-Fi + Cellular";
/** iPad (9.7 inch - 6th generation 2018) */
if ([hardware isEqualToString:@"iPad7,5"]) return @"iPad 6 Wi-Fi";
if ([hardware isEqualToString:@"iPad7,6"]) return @"iPad 6 Wi-Fi + Cellular";
/** iPad (10.2 inch - 7th generation 2019) */
if ([hardware isEqualToString:@"iPad7,11"]) return @"iPad 7 Wi-Fi";
if ([hardware isEqualToString:@"iPad7,12"]) return @"iPad 7 Wi-Fi + Cellular";
/** iPad mini */
if ([hardware isEqualToString:@"iPad2,5"]) return @"iPad mini Wi-Fi";
if ([hardware isEqualToString:@"iPad2,6"]) return @"iPad mini Wi-Fi + Cellular";
if ([hardware isEqualToString:@"iPad2,7"]) return @"iPad mini Wi-Fi + Cellular (MM)";
/** iPad mini 2 */
if ([hardware isEqualToString:@"iPad4,4"]) return @"iPad mini 2 Wi-Fi";
if ([hardware isEqualToString:@"iPad4,5"]) return @"iPad mini 2 Wi-Fi + Cellular";
if ([hardware isEqualToString:@"iPad4,6"]) return @"iPad mini 2 Wi-Fi + Cellular (TD-LTE)";
/** iPad mini 3 */
if ([hardware isEqualToString:@"iPad4,7"]) return @"iPad mini 3 Wi-Fi";
if ([hardware isEqualToString:@"iPad4,8"]) return @"iPad mini 3 Wi-Fi + Cellular";
if ([hardware isEqualToString:@"iPad4,9"]) return @"iPad mini 3 Wi-Fi + Cellular (TD-LTE)";
/** iPad mini 4 */
if ([hardware isEqualToString:@"iPad5,1"]) return @"iPad mini 4";
if ([hardware isEqualToString:@"iPad5,2"]) return @"iPad mini 4 Wi-Fi + Cellular";
/** iPad mini 5 */
if ([hardware isEqualToString:@"iPad11,1"]) return @"iPad mini 5 Wi-Fi";
if ([hardware isEqualToString:@"iPad11,2"]) return @"iPad mini 5 Wi-Fi + Cellular";
/** iPad Pro (9.7 inch) */
if ([hardware isEqualToString:@"iPad6,3"]) return @"iPad Pro (9.7-inch)";
if ([hardware isEqualToString:@"iPad6,4"]) return @"iPad Pro (9.7-inch) Wi-Fi + Cellular";
/** iPad Pro (10.5-inch) */
if ([hardware isEqualToString:@"iPad7,3"]) return @"iPad Pro (10.5-inch)";
if ([hardware isEqualToString:@"iPad7,4"]) return @"iPad Pro (10.5-inch) Wi-Fi + Cellular";
/** iPad Pro 12.9-inch */
if ([hardware isEqualToString:@"iPad6,7"]) return @"iPad Pro 12.9-inch";
if ([hardware isEqualToString:@"iPad6,8"]) return @"iPad Pro 12.9-inch Wi-Fi + Cellular";
/** iPad Pro 12.9-inch (2nd generation) */
if ([hardware isEqualToString:@"iPad7,1"]) return @"iPad Pro 12.9-inch (2nd generation)";
if ([hardware isEqualToString:@"iPad7,2"]) return @"iPad Pro 12.9-inch (2nd generation) Wi-Fi + Cellular";
/** iPad Pro 12.9-inch (3rd generation) */
if ([hardware isEqualToString:@"iPad8,5"] ||
[hardware isEqualToString:@"iPad8,6"]) return @"iPad Pro 12.9-inch (3rd generation)";
if ([hardware isEqualToString:@"iPad8,7"] ||
[hardware isEqualToString:@"iPad8,8"]) return @"iPad Pro 12.9-inch (3rd generation Wi-Fi + Cellular)";
/** iPad Pro 11-inch */
if ([hardware isEqualToString:@"iPad8,1"] ||
[hardware isEqualToString:@"iPad8,2"]) return @"iPad Pro 11-inch";
if ([hardware isEqualToString:@"iPad8,3"] ||
[hardware isEqualToString:@"iPad8,4"]) return @"iPad Pro 11-inch Wi-Fi + Cellular";
}
else if ([hardware hasPrefix:@"AppleTV"]) {
if ([hardware isEqualToString:@"AppleTV2,1"]) return @"Apple TV 2";
if ([hardware isEqualToString:@"AppleTV3,1"]) return @"Apple TV 3";
if ([hardware isEqualToString:@"AppleTV3,2"]) return @"Apple TV 3";
if ([hardware isEqualToString:@"AppleTV5,3"]) return @"Apple TV 4";
}
/** If none was found, send the original string */
return hardware ?: @"Unknown";
}
NSString *wb_hardware_machine() {
size_t size;
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
char *name = malloc(size);
sysctlbyname("hw.machine", name, &size, NULL, 0);
NSString *machine = [NSString stringWithCString:name encoding:NSUTF8StringEncoding];
free(name);
return machine;
}
- 参考:https://github.com/dannycabrera/Get-iOS-Model/blob/master/iOSHardware.cs