I'm using the below code to get the device name
NSString* code = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
Which gives the result as follows and mapped to devices
@"iPhone9,1" :@"iPhone 7",
@"iPhone9,3" :@"iPhone 7",
@"iPhone9,2" :@"iPhone 7 Plus",
@"iPhone9,4" :@"iPhone 7 Plus",
Do we have the new device code for the new devices that are released (iPhone 8, iPhone 8 Plus and iPhone X)
Edit: This has been corrected. The iPhone X is NOT iPhone10,5 and iPhone10,6.
iPhone10,1
& iPhone10,4
iPhone10,2
& iPhone10,5
iPhone10,3
& iPhone10,6
NOTE: See Obj-C code for the newest device additions.
import Foundation
import SystemConfiguration
class DeviceInfo {
static func platform() -> String? {
var systemInfo = utsname()
uname(&systemInfo)
let modelCode = withUnsafePointer(to: &systemInfo.machine) {
$0.withMemoryRebound(to: CChar.self, capacity: 1) {
ptr in String.init(validatingUTF8: ptr)
}
}
return modelCode
}
static func deviceType() -> String {
if let platform = platform(), let device = deviceDict[platform] {
return device
}
return "unknown"
}
static let deviceDict: Dictionary<String, String> = [
"iPhone1,1" : "iPhone (1st generation)",
"iPhone1,2" : "iPhone 3G",
"iPhone2,1" : "iPhone 3GS",
"iPhone3,1" : "iPhone 4 (GSM)",
"iPhone3,2" : "iPhone 4 (GSM, 2nd revision)",
"iPhone3,3" : "iPhone 4 (Verizon)",
"iPhone4,1" : "iPhone 4S",
"iPhone5,1" : "iPhone 5 (GSM)",
"iPhone5,2" : "iPhone 5 (GSM+CDMA)",
"iPhone5,3" : "iPhone 5c (GSM)",
"iPhone5,4" : "iPhone 5c (GSM+CDMA)",
"iPhone6,1" : "iPhone 5s (GSM)",
"iPhone6,2" : "iPhone 5s (GSM+CDMA)",
"iPhone7,2" : "iPhone 6",
"iPhone7,1" : "iPhone 6 Plus",
"iPhone8,1" : "iPhone 6s",
"iPhone8,2" : "iPhone 6s Plus",
"iPhone8,4" : "iPhone SE",
"iPhone9,1" : "iPhone 7 (GSM+CDMA)",
"iPhone9,3" : "iPhone 7 (GSM)",
"iPhone9,2" : "iPhone 7 Plus (GSM+CDMA)",
"iPhone9,4" : "iPhone 7 Plus (GSM)",
"iPhone10,1" : "iPhone 8 (GSM+CDMA)",
"iPhone10,4" : "iPhone 8 (GSM)",
"iPhone10,2" : "iPhone 8 Plus (GSM+CDMA)",
"iPhone10,5" : "iPhone 8 Plus (GSM)",
"iPhone10,3" : "iPhone X (GSM+CDMA)",
"iPhone10,6" : "iPhone X (GSM)",
"iPhone11,1" : "iPhone XR (GSM+CDMA)",
"iPhone11,2" : "iPhone XS (GSM+CDMA)",
"iPhone11,3" : "iPhone XS (GSM)",
"iPhone11,4" : "iPhone XS Max (GSM+CDMA)",
"iPhone11,5" : "iPhone XS Max (GSM, Dual Sim, China)",
"iPhone11,6" : "iPhone XS Max (GSM)",
"iPhone11,8" : "iPhone XR (GSM)",
"iPod1,1" : "iPod Touch 1G",
"iPod2,1" : "iPod Touch 2G",
"iPod3,1" : "iPod Touch 3G",
"iPod4,1" : "iPod Touch 4G",
"iPod5,1" : "iPod Touch 5G",
"iPod7,1" : "iPod Touch 6G",
"iPad1,1" : "iPad",
"iPad2,1" : "iPad 2 (WiFi)",
"iPad2,2" : "iPad 2 (GSM)",
"iPad2,3" : "iPad 2 (CDMA)",
"iPad2,4" : "iPad 2 (WiFi)",
"iPad2,5" : "iPad Mini (WiFi)",
"iPad2,6" : "iPad Mini (GSM)",
"iPad2,7" : "iPad Mini (CDMA)",
"iPad3,1" : "iPad 3 (WiFi)",
"iPad3,2" : "iPad 3 (CDMA)",
"iPad3,3" : "iPad 3 (GSM)",
"iPad3,4" : "iPad 4 (WiFi)",
"iPad3,5" : "iPad 4 (GSM)",
"iPad3,6" : "iPad 4 (CDMA)",
"iPad4,1" : "iPad Air (WiFi)",
"iPad4,2" : "iPad Air (GSM)",
"iPad4,3" : "iPad Air (CDMA)",
"iPad4,4" : "iPad Mini 2 (WiFi)",
"iPad4,5" : "iPad Mini 2 (Cellular)",
"iPad4,6" : "iPad Mini 2 (Cellular)",
"iPad4,7" : "iPad Mini 3 (WiFi)",
"iPad4,8" : "iPad Mini 3 (Cellular)",
"iPad4,9" : "iPad Mini 3 (Cellular)",
"iPad5,1" : "iPad Mini 4 (WiFi)",
"iPad5,2" : "iPad Mini 4 (Cellular)",
"iPad5,3" : "iPad Air 2 (WiFi)",
"iPad5,4" : "iPad Air 2 (Cellular)",
"iPad6,3" : "iPad Pro 9.7-inch (WiFi)",
"iPad6,4" : "iPad Pro 9.7-inch (Cellular)",
"iPad6,7" : "iPad Pro 12.9-inch (WiFi)",
"iPad6,8" : "iPad Pro 12.9-inch (Cellular)",
"iPad6,11" : "iPad 5 (WiFi)",
"iPad6,12" : "iPad 5 (Cellular)",
"iPad7,1" : "iPad Pro 12.9-inch 2 (WiFi)",
"iPad7,2" : "iPad Pro 12.9-inch 2 (Cellular)",
"iPad7,3" : "iPad Pro 10.5-inch (WiFi)",
"iPad7,4" : "iPad Pro 10.5-inch (Cellular)",
"iPad7,5" : "iPad 6 (WiFi)",
"iPad7,6" : "iPad 6 (Cellular)",
"iPad8,1" : "iPad Pro 11-inch (WiFi)",
"iPad8,2" : "iPad Pro 11-inch (WiFi, 1TB)",
"iPad8,3" : "iPad Pro 11-inch (Cellular)",
"iPad8,4" : "iPad Pro 11-inch (Cellular, 1TB)",
"iPad8,5" : "iPad Pro 12.9-inch 3 (WiFi)",
"iPad8,6" : "iPad Pro 12.9-inch 3 (WiFi, 1TB)",
"iPad8,7" : "iPad Pro 12.9-inch 3 (Cellular)",
"iPad8,8" : "iPad Pro 12.9-inch 3 (Cellular, 1TB)",
"i386" : "Simulator",
"x86_64" : "Simulator",
]
}
I will update the answer when I have the new watches platform strings.
+ (NSString *)platformString{
NSString *platform = [Settings platform];
//iPhone
if ([platform isEqualToString:@"iPhone1,1"]) return @"iPhone (1st generation)";
if ([platform isEqualToString:@"iPhone1,2"]) return @"iPhone 3G";
if ([platform isEqualToString:@"iPhone2,1"]) return @"iPhone 3GS";
if ([platform isEqualToString:@"iPhone3,1"]) return @"iPhone 4 (GSM)";
if ([platform isEqualToString:@"iPhone3,2"]) return @"iPhone 4 (GSM, 2nd revision)";
if ([platform isEqualToString:@"iPhone3,3"]) return @"iPhone 4 (Verizon)";
if ([platform isEqualToString:@"iPhone4,1"]) return @"iPhone 4S";
if ([platform isEqualToString:@"iPhone5,1"]) return @"iPhone 5 (GSM)";
if ([platform isEqualToString:@"iPhone5,2"]) return @"iPhone 5 (GSM+CDMA)";
if ([platform isEqualToString:@"iPhone5,3"]) return @"iPhone 5c (GSM)";
if ([platform isEqualToString:@"iPhone5,4"]) return @"iPhone 5c (GSM+CDMA)";
if ([platform isEqualToString:@"iPhone6,1"]) return @"iPhone 5s (GSM)";
if ([platform isEqualToString:@"iPhone6,2"]) return @"iPhone 5s (GSM+CDMA)";
if ([platform isEqualToString:@"iPhone7,2"]) return @"iPhone 6";
if ([platform isEqualToString:@"iPhone7,1"]) 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 (GSM+CDMA)";
if ([platform isEqualToString:@"iPhone9,3"]) return @"iPhone 7 (GSM)";
if ([platform isEqualToString:@"iPhone9,2"]) return @"iPhone 7 Plus (GSM+CDMA)";
if ([platform isEqualToString:@"iPhone9,4"]) return @"iPhone 7 Plus (GSM)";
if ([platform isEqualToString:@"iPhone10,1"]) return @"iPhone 8 (GSM+CDMA)";
if ([platform isEqualToString:@"iPhone10,4"]) return @"iPhone 8 (GSM)";
if ([platform isEqualToString:@"iPhone10,2"]) return @"iPhone 8 Plus (GSM+CDMA)";
if ([platform isEqualToString:@"iPhone10,5"]) return @"iPhone 8 Plus (GSM)";
if ([platform isEqualToString:@"iPhone10,3"]) return @"iPhone X (GSM+CDMA)";
if ([platform isEqualToString:@"iPhone10,6"]) return @"iPhone X (GSM)";
if ([platform isEqualToString:@"iPhone11,1"]) return @"iPhone XR (GSM+CDMA)";
if ([platform isEqualToString:@"iPhone11,2"]) return @"iPhone XS (GSM+CDMA)";
if ([platform isEqualToString:@"iPhone11,3"]) return @"iPhone XS (GSM)";
if ([platform isEqualToString:@"iPhone11,4"]) return @"iPhone XS Max (GSM+CDMA)";
if ([platform isEqualToString:@"iPhone11,5"]) return @"iPhone XS Max (GSM, Dual Sim, China)";
if ([platform isEqualToString:@"iPhone11,6"]) return @"iPhone XS Max (GSM)";
if ([platform isEqualToString:@"iPhone11,8"]) return @"iPhone XR (GSM)";
if ([platform isEqualToString:@"iPhone12,1"]) return @"iPhone 11";
if ([platform isEqualToString:@"iPhone12,2"]) return @"iPhone 11 Pro";
if ([platform isEqualToString:@"iPhone12,3"]) return @"iPhone 11 Pro Max";
if ([platform isEqualToString:@"iPhone12,5"]) return @"iPhone 11 Pro Max";
if ([platform isEqualToString:@"iPhone12,8"]) return @"iPhone SE 2nd Gen.";
//iPod Touch
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:@"iPod7,1"]) return @"iPod Touch 6G";
if ([platform isEqualToString:@"iPod9,1"]) return @"iPod Touch (7G)";
//iPad
if ([platform isEqualToString:@"iPad1,1"]) return @"iPad (1st generation)";
if ([platform isEqualToString:@"iPad2,1"]) return @"iPad 2 (Wi-Fi)";
if ([platform isEqualToString:@"iPad2,2"]) return @"iPad 2 (GSM)";
if ([platform isEqualToString:@"iPad2,3"]) return @"iPad 2 (CDMA)";
if ([platform isEqualToString:@"iPad2,4"]) return @"iPad 2 (Wi-Fi, Mid 2012)";
if ([platform isEqualToString:@"iPad2,5"]) return @"iPad Mini (Wi-Fi)";
if ([platform isEqualToString:@"iPad2,6"]) return @"iPad Mini (GSM)";
if ([platform isEqualToString:@"iPad2,7"]) return @"iPad Mini (GSM+CDMA)";
if ([platform isEqualToString:@"iPad3,1"]) return @"iPad (3rd generation) (Wi-Fi)";
if ([platform isEqualToString:@"iPad3,2"]) return @"iPad (3rd generation) (GSM+CDMA)";
if ([platform isEqualToString:@"iPad3,3"]) return @"iPad (3rd generation) (GSM)";
if ([platform isEqualToString:@"iPad3,4"]) return @"iPad (4th generation) (Wi-Fi)";
if ([platform isEqualToString:@"iPad3,5"]) return @"iPad (4th generation) (GSM)";
if ([platform isEqualToString:@"iPad3,6"]) return @"iPad (4th generation) (GSM+CDMA)";
if ([platform isEqualToString:@"iPad4,1"]) return @"iPad Air (Wi-Fi)";
if ([platform isEqualToString:@"iPad4,2"]) return @"iPad Air (Cellular)";
if ([platform isEqualToString:@"iPad4,3"]) return @"iPad Air (China)";
if ([platform isEqualToString:@"iPad4,4"]) return @"iPad Mini 2 (Wi-Fi)";
if ([platform isEqualToString:@"iPad4,5"]) return @"iPad Mini 2 (Cellular)";
if ([platform isEqualToString:@"iPad4,6"]) return @"iPad Mini 2 (China)";
if ([platform isEqualToString:@"iPad4,7"]) return @"iPad Mini 3 (Wi-Fi)";
if ([platform isEqualToString:@"iPad4,8"]) return @"iPad Mini 3 (Cellular)";
if ([platform isEqualToString:@"iPad4,9"]) return @"iPad Mini 3 (China)";
if ([platform isEqualToString:@"iPad5,1"]) return @"iPad Mini 4 (Wi-Fi)";
if ([platform isEqualToString:@"iPad5,2"]) return @"iPad Mini 4 (Cellular)";
if ([platform isEqualToString:@"iPad5,3"]) return @"iPad Air 2 (Wi-Fi)";
if ([platform isEqualToString:@"iPad5,4"]) return @"iPad Air 2 (Cellular)";
if ([platform isEqualToString:@"iPad6,3"]) return @"iPad Pro 9.7\" (Wi-Fi)";
if ([platform isEqualToString:@"iPad6,4"]) return @"iPad Pro 9.7\" (Cellular)";
if ([platform isEqualToString:@"iPad6,7"]) return @"iPad Pro 12.9\" (Wi-Fi)";
if ([platform isEqualToString:@"iPad6,8"]) return @"iPad Pro 12.9\" (Cellular)";
if ([platform isEqualToString:@"iPad6,11"]) return @"iPad (5th generation) (Wi-Fi)";
if ([platform isEqualToString:@"iPad6,12"]) return @"iPad (5th generation) (Cellular)";
if ([platform isEqualToString:@"iPad7,1"]) return @"iPad Pro 12.9\" (2nd generation) (Wi-Fi)";
if ([platform isEqualToString:@"iPad7,2"]) return @"iPad Pro 12.9\" (2nd generation) (Cellular)";
if ([platform isEqualToString:@"iPad7,3"]) return @"iPad Pro 10.5\" (Wi-Fi)";
if ([platform isEqualToString:@"iPad7,4"]) return @"iPad Pro 10.5\" (Cellular)";
if ([platform isEqualToString:@"iPad7,5"]) return @"iPad 6 (WiFi)";
if ([platform isEqualToString:@"iPad7,6"]) return @"iPad 6 (Cellular)";
if ([platform isEqualToString:@"iPad8,1"]) return @"iPad Pro 11\" (2018) (Wi-Fi)";
if ([platform isEqualToString:@"iPad8,2"]) return @"iPad Pro 11\" (2018) (Wi-Fi, 1TB)";
if ([platform isEqualToString:@"iPad8,3"]) return @"iPad Pro 11\" (2018) (Wi-Fi)";
if ([platform isEqualToString:@"iPad8,4"]) return @"iPad Pro 11\" (2018) (Cellular)";
if ([platform isEqualToString:@"iPad8,5"]) return @"iPad Pro 12.9\" (2018) (3rd generation) (Wi-Fi)";
if ([platform isEqualToString:@"iPad8,6"]) return @"iPad Pro 12.9\" (2018) (3rd generation) (Cellular)";
if ([platform isEqualToString:@"iPad8,7"]) return @"iPad Pro 12.9\" (2018) (3rd generation) (Wi-Fi, 1TB)";
if ([platform isEqualToString:@"iPad8,8"]) return @"iPad Pro 12.9\" (2018) (3rd generation) (Cellular, 1TB)";
if ([platform isEqualToString:@"iPad11,1"]) return @"iPad mini (2019) (5th generation) (Wi-Fi)";
if ([platform isEqualToString:@"iPad11,2"]) return @"iPad mini (2019) (5th generation) (Cellular)";
if ([platform isEqualToString:@"iPad11,3"]) return @"iPad Air (2019) (3rd generation) (Wi-Fi)";
if ([platform isEqualToString:@"iPad11,4"]) return @"iPad Air (2019) (3rd generation) (Cellular)";
//Apple TV
if ([platform isEqualToString:@"AppleTV2,1"]) return @"Apple TV 2G";
if ([platform isEqualToString:@"AppleTV3,1"]) return @"Apple TV 3";
if ([platform isEqualToString:@"AppleTV3,2"]) return @"Apple TV 3 (2013)";
if ([platform isEqualToString:@"AppleTV5,3"]) return @"Apple TV 4";
if ([platform isEqualToString:@"AppleTV6,2"]) return @"Apple TV 4K";
//Apple Watch
if ([platform isEqualToString:@"Watch1,1"]) return @"Apple Watch (1st generation) (38mm)";
if ([platform isEqualToString:@"Watch1,2"]) return @"Apple Watch (1st generation) (42mm)";
if ([platform isEqualToString:@"Watch2,6"]) return @"Apple Watch Series 1 (38mm)";
if ([platform isEqualToString:@"Watch2,7"]) return @"Apple Watch Series 1 (42mm)";
if ([platform isEqualToString:@"Watch2,3"]) return @"Apple Watch Series 2 (38mm)";
if ([platform isEqualToString:@"Watch2,4"]) return @"Apple Watch Series 2 (42mm)";
if ([platform isEqualToString:@"Watch3,1"]) return @"Apple Watch Series 3 (38mm Cellular)";
if ([platform isEqualToString:@"Watch3,2"]) return @"Apple Watch Series 3 (42mm Cellular)";
if ([platform isEqualToString:@"Watch3,3"]) return @"Apple Watch Series 3 (38mm)";
if ([platform isEqualToString:@"Watch3,4"]) return @"Apple Watch Series 3 (42mm)";
if ([platform isEqualToString:@"Watch4,1"]) return @"Apple Watch Series 4 (40mm)";
if ([platform isEqualToString:@"Watch4,2"]) return @"Apple Watch Series 4 (44mm)";
if ([platform isEqualToString:@"Watch4,3"]) return @"Apple Watch Series 4 (40mm Cellular)";
if ([platform isEqualToString:@"Watch4,4"]) return @"Apple Watch Series 4 (44mm Cellular)";
if ([platform isEqualToString:@"Watch5,1"]) return @"Apple Watch Series 5 (40mm)";
if ([platform isEqualToString:@"Watch5,2"]) return @"Apple Watch Series 5 (44mm)";
if ([platform isEqualToString:@"Watch5,3"]) return @"Apple Watch Series 5 (40mm Cellular)";
if ([platform isEqualToString:@"Watch5,4"]) return @"Apple Watch Series 5 (44mm Cellular)";
//Simulator
if ([platform isEqualToString:@"i386"]) return @"Simulator";
if ([platform isEqualToString:@"x86_64"]) return @"Simulator";
return platform;
return [@"Unknown : " stringByAppendingString:platform];
}
This is the actual code to get the devices platform.
Note the class methods
and the code is inside an NSObject Class
called Settings
.
You may easily change it to an instance method
with the first line - (NSString *)platform {
and - (NSString *)platformString {
, also call the platform: NSString *platform = [self platform];
at the top of the platformString
code.
+ (NSString *) platform{
int mib[2];
size_t len;
char *machine;
mib[0] = CTL_HW;
mib[1] = HW_MACHINE;
sysctl(mib, 2u, NULL, &len, NULL, 0);
machine = malloc(len);
sysctl(mib, 2u, machine, &len, NULL, 0);
NSString *platform = @(machine);
free(machine);
return platform;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With