Skip to content

Instantly share code, notes, and snippets.

@liamnichols
Created October 30, 2013 17:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save liamnichols/7236570 to your computer and use it in GitHub Desktop.
Save liamnichols/7236570 to your computer and use it in GitHub Desktop.
// System Device Type (iPhone1,0) (Formatted = iPhone 1)
+ (NSString *)systemDeviceTypeFormatted:(BOOL)formatted {
// Set up a Device Type String
NSString *DeviceType;
// Check if it should be formatted
if (formatted) {
// Formatted
@try {
// Set up a new Device Type String
NSString *NewDeviceType;
// Set up a struct
struct utsname DT;
// Get the system information
uname(&DT);
// Set the device type to the machine type
DeviceType = [NSString stringWithFormat:@"%s", DT.machine];
//Simulators
if ([DeviceType isEqualToString:@"i386"]) NewDeviceType = @"iPhone Simulator";
else if ([DeviceType isEqualToString:@"x86_64"]) NewDeviceType = @"iPhone Simulator";
//iPhones
else if ([DeviceType isEqualToString:@"iPhone1,1"]) NewDeviceType = @"iPhone";
else if ([DeviceType isEqualToString:@"iPhone1,2"]) NewDeviceType = @"iPhone 3G";
else if ([DeviceType isEqualToString:@"iPhone2,1"]) NewDeviceType = @"iPhone 3GS";
else if ([DeviceType isEqualToString:@"iPhone3,1"]) NewDeviceType = @"iPhone 4 (GSM)";
else if ([DeviceType isEqualToString:@"iPhone3,3"]) NewDeviceType = @"iPhone 4 (CDMA)";
else if ([DeviceType isEqualToString:@"iPhone4,1"]) NewDeviceType = @"iPhone 4S";
else if ([DeviceType isEqualToString:@"iPhone5,1"]) NewDeviceType = @"iPhone 5 (GSM)";
else if ([DeviceType isEqualToString:@"iPhone5,2"]) NewDeviceType = @"iPhone 5 (GSM+CDMA)";
else if ([DeviceType isEqualToString:@"iPhone5,3"]) NewDeviceType = @"iPhone 5c";
else if ([DeviceType isEqualToString:@"iPhone5,4"]) NewDeviceType = @"iPhone 5c";
else if ([DeviceType isEqualToString:@"iPhone6,1"]) NewDeviceType = @"iPhone 5s";
else if ([DeviceType isEqualToString:@"iPhone6,2"]) NewDeviceType = @"iPhone 5s";
//iPods
else if ([DeviceType isEqualToString:@"iPod1,1"]) NewDeviceType = @"iPod Touch 1st Gen";
else if ([DeviceType isEqualToString:@"iPod2,1"]) NewDeviceType = @"iPod Touch 2nd Gen";
else if ([DeviceType isEqualToString:@"iPod3,1"]) NewDeviceType = @"iPod Touch 3rd Gen";
else if ([DeviceType isEqualToString:@"iPod4,1"]) NewDeviceType = @"iPod Touch 4th Gen";
else if ([DeviceType isEqualToString:@"iPod5,1"]) NewDeviceType = @"iPod Touch 5th Gen";
//iPads
//1st Generation
else if ([DeviceType isEqualToString:@"iPad1,1"]) NewDeviceType = @"iPad";
//2nd Generation
else if ([DeviceType isEqualToString:@"iPad2,1"]) NewDeviceType = @"iPad 2 (WiFi)";
else if ([DeviceType isEqualToString:@"iPad2,2"]) NewDeviceType = @"iPad 2 (GSM)";
else if ([DeviceType isEqualToString:@"iPad2,3"]) NewDeviceType = @"iPad 2 (CDMA)";
else if ([DeviceType isEqualToString:@"iPad2,4"]) NewDeviceType = @"iPad 2 (WiFi Rev 2)";
//3rd Generation
else if ([DeviceType isEqualToString:@"iPad3,1"]) NewDeviceType = @"iPad 3 (WiFi)";
else if ([DeviceType isEqualToString:@"iPad3,2"]) NewDeviceType = @"iPad 3 (CDMA)";
else if ([DeviceType isEqualToString:@"iPad3,3"]) NewDeviceType = @"iPad 3 (GSM)";
//4th Generation
else if ([DeviceType isEqualToString:@"iPad3,4"]) NewDeviceType = @"iPad 4 (WiFi)";
else if ([DeviceType isEqualToString:@"iPad3,5"]) NewDeviceType = @"iPad 4 (GSM)";
else if ([DeviceType isEqualToString:@"iPad3,6"]) NewDeviceType = @"iPad 4 (GSM+CDMA)";
//iPad Minis
//1st Generation
else if ([DeviceType isEqualToString:@"iPad2,5"]) NewDeviceType = @"iPad Mini (WiFi)";
else if ([DeviceType isEqualToString:@"iPad2,6"]) NewDeviceType = @"iPad Mini (GSM)";
else if ([DeviceType isEqualToString:@"iPad2,7"]) NewDeviceType = @"iPad Mini (GSM+CDMA)";
//Unknown
else NewDeviceType = @"Unknown";
// Return the new device type
return NewDeviceType;
}
@catch (NSException *exception) {
// Error
return nil;
}
} else {
// Unformatted
@try {
// Set up a struct
struct utsname DT;
// Get the system information
uname(&DT);
// Set the device type to the machine type
DeviceType = [NSString stringWithFormat:@"%s", DT.machine];
// Return the device type
return DeviceType;
}
@catch (NSException *exception) {
// Error
return nil;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment