Determine device (iPhone, iPod Touch) with iOS - ios

Is there a way to determine the device running an application. I want to distinguish between iPhone and iPod Touch, if possible.

You can use the UIDevice class like this:
NSString *deviceType = [UIDevice currentDevice].model;
if([deviceType isEqualToString:#"iPhone"])
// it's an iPhone

This is an update for UIDeviceHardware.m from the answer above.
- (NSString *)platformString
{
NSString *platform = [self platform];
if ([platform isEqualToString:#"iPhone1,1"]) return #"iPhone 1G";
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,3"]) return #"Verizon iPhone 4";
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,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:#"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:#"iPad1,1"]) return #"iPad";
if ([platform isEqualToString:#"iPad2,1"]) return #"iPad 2 (WiFi)";
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 (WiFi)";
if ([platform isEqualToString:#"iPad2,5"]) return #"iPad Mini (WiFi)";
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 3 (WiFi)";
if ([platform isEqualToString:#"iPad3,2"]) return #"iPad 3 (GSM+CDMA)";
if ([platform isEqualToString:#"iPad3,3"]) return #"iPad 3 (GSM)";
if ([platform isEqualToString:#"iPad3,4"]) return #"iPad 4 (WiFi)";
if ([platform isEqualToString:#"iPad3,5"]) return #"iPad 4 (GSM)";
if ([platform isEqualToString:#"iPad3,6"]) return #"iPad 4 (GSM+CDMA)";
if ([platform isEqualToString:#"iPad4,1"]) return #"iPad Air (WiFi)";
if ([platform isEqualToString:#"iPad4,2"]) return #"iPad Air (Cellular)";
if ([platform isEqualToString:#"iPad4,4"]) return #"iPad mini 2G (WiFi)";
if ([platform isEqualToString:#"iPad4,5"]) return #"iPad mini 2G (Cellular)";
if ([platform isEqualToString:#"iPad5,1"]) return #"iPad mini 4 (WiFi)";
if ([platform isEqualToString:#"iPad5,2"]) return #"iPad mini 4 (Cellular)";
if ([platform isEqualToString:#"iPad5,3"]) return #"iPad Air 2 (WiFi)";
if ([platform isEqualToString:#"iPad5,4"]) return #"iPad Air 2 (Cellular)";
if ([platform isEqualToString:#"iPad6,3"]) return #"iPad Pro 9.7 inch (WiFi)";
if ([platform isEqualToString:#"iPad6,4"]) return #"iPad Pro 9.7 inch (Cellular)";
if ([platform isEqualToString:#"iPad6,7"]) return #"iPad Pro 12.9 inch (WiFi)";
if ([platform isEqualToString:#"iPad6,8"]) return #"iPad Pro 12.9 inch (Cellular)";
if ([platform isEqualToString:#"i386"]) return #"Simulator";
if ([platform isEqualToString:#"x86_64"]) return #"Simulator";
return platform;
}

Please feel free to use this class (gist # github)
CODE REMOVED AND RELOCATED TO
https://gist.github.com/1323251
UPDATE (01/14/11)
Obviously, this code is a bit out of date by now, but it can certainly be updated using the code on this thread provided by Brian Robbins which includes similar code with updated models. Thanks for the support on this thread.

I use this in my app. Up to date as of December 2012.
- (NSString *) platformString {
// Gets a string with the device model
size_t size;
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
char *machine = malloc(size);
sysctlbyname("hw.machine", machine, &size, NULL, 0);
NSString *platform = [NSString stringWithCString:machine encoding:NSUTF8StringEncoding];
free(machine);
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 (CDMA)";
if ([platform isEqualToString:#"iPhone4,1"]) return #"iPhone 4S";
if ([platform isEqualToString:#"iPhone5,1"]) return #"iPhone 5";
if ([platform isEqualToString:#"iPhone5,2"]) return #"iPhone 5 (GSM+CDMA)";
if ([platform isEqualToString:#"iPod1,1"]) return #"iPod Touch (1 Gen)";
if ([platform isEqualToString:#"iPod2,1"]) return #"iPod Touch (2 Gen)";
if ([platform isEqualToString:#"iPod3,1"]) return #"iPod Touch (3 Gen)";
if ([platform isEqualToString:#"iPod4,1"]) return #"iPod Touch (4 Gen)";
if ([platform isEqualToString:#"iPod5,1"]) return #"iPod Touch (5 Gen)";
if ([platform isEqualToString:#"iPad1,1"]) return #"iPad";
if ([platform isEqualToString:#"iPad1,2"]) return #"iPad 3G";
if ([platform isEqualToString:#"iPad2,1"]) return #"iPad 2 (WiFi)";
if ([platform isEqualToString:#"iPad2,2"]) return #"iPad 2";
if ([platform isEqualToString:#"iPad2,3"]) return #"iPad 2 (CDMA)";
if ([platform isEqualToString:#"iPad2,4"]) return #"iPad 2";
if ([platform isEqualToString:#"iPad2,5"]) return #"iPad Mini (WiFi)";
if ([platform isEqualToString:#"iPad2,6"]) return #"iPad Mini";
if ([platform isEqualToString:#"iPad2,7"]) return #"iPad Mini (GSM+CDMA)";
if ([platform isEqualToString:#"iPad3,1"]) return #"iPad 3 (WiFi)";
if ([platform isEqualToString:#"iPad3,2"]) return #"iPad 3 (GSM+CDMA)";
if ([platform isEqualToString:#"iPad3,3"]) return #"iPad 3";
if ([platform isEqualToString:#"iPad3,4"]) return #"iPad 4 (WiFi)";
if ([platform isEqualToString:#"iPad3,5"]) return #"iPad 4";
if ([platform isEqualToString:#"iPad3,6"]) return #"iPad 4 (GSM+CDMA)";
if ([platform isEqualToString:#"i386"]) return #"Simulator";
if ([platform isEqualToString:#"x86_64"]) return #"Simulator";
return platform;
}

Latest update - February 2023: Added iPhone 14, iPhone 14 Plus, iPhone 14 Pro, iPhone 14 Pro Max, iPad (10th generation), iPad Pro 11" (4rd generation), iPad Pro 12,9" (6th generation), Apple Watch Series 8, Apple Watch Ultra, Apple Watch SE (2nd generation).
Removed devices that don't support iOS 10
Swift
(Tested on Swift 5, Swift 4, Swift 3)
The function below returns a string with current device name.
func userDeviceName() -> String {
let platform: String = {
var size = 0
sysctlbyname("hw.machine", nil, &size, nil, 0)
var machine = [CChar](repeating: 0, count: Int(size))
sysctlbyname("hw.machine", &machine, &size, nil, 0)
return String(cString: machine)
}()
let deviceMap = [
// iPhone
"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,2": "iPhone XS",
"iPhone11,6": "iPhone XS Max",
"iPhone11,8": "iPhone XR",
"iPhone12,1": "iPhone 11",
"iPhone12,3": "iPhone 11 Pro",
"iPhone12,5": "iPhone 11 Pro Max",
"iPhone12,8": "iPhone SE (2nd generation)",
"iPhone13,1": "iPhone 12 mini",
"iPhone13,2": "iPhone 12",
"iPhone13,3": "iPhone 12 Pro",
"iPhone13,4": "iPhone 12 Pro Max",
"iPhone14,4": "iPhone 13 mini",
"iPhone14,5": "iPhone 13",
"iPhone14,2": "iPhone 13 Pro",
"iPhone14,3": "iPhone 13 Pro Max",
"iPhone14,6": "iPhone SE (3rd generation) (2022)",
"iPhone14,7": "iPhone 14",
"iPhone14,8": "iPhone 14 Plus",
"iPhone15,2": "iPhone 14 Pro",
"iPhone15,3": "iPhone 14 Pro Max",
// iPod touch
"iPod7,1": "iPod Touch (6th generation)",
"iPod9,1": "iPod Touch (7th generation) (2019)",
// iPad
"iPad3,4": "iPad (4th generation) (Wi-Fi)",
"iPad3,5": "iPad (4th generation) (GSM)",
"iPad3,6": "iPad (4th generation) (GSM+CDMA)",
"iPad6,11": "iPad (5th generation) 9.7\" (2017) (Wi-Fi)",
"iPad6,12": "iPad (5th generation) 9.7\" (2017) (Cellular)",
"iPad7,5": "iPad (6th generation) 9.7\" (2018) (Wi-Fi)",
"iPad7,6": "iPad (6th generation) 9.7\" (2018) (Cellular)",
"iPad7,11": "iPad (7th generation) 10.2\" (2019) (Wi-Fi)",
"iPad7,12": "iPad (7th generation) 10.2\" (2019) (Cellular)",
"iPad11,6": "iPad (8th generation) 10.2\" (2020) (Wi-Fi)",
"iPad11,7": "iPad (8th generation) 10.2\" (2020) (Cellular)",
"iPad12,1": "iPad (9th generation) 10.2\" (2021) (Wi-Fi)",
"iPad12,2": "iPad (9th generation) 10.2\" (2021) (Cellular)",
"iPad13,18": "iPad (10th generation) 10.9\" (2022) (Wi-Fi)",
"iPad13,19": "iPad (10th generation) 10.9\" (2022) (Cellular)",
// iPad Air
"iPad4,1": "iPad Air (Wi-Fi)",
"iPad4,2": "iPad Air (Cellular)",
"iPad4,3": "iPad Air (China)",
"iPad5,3": "iPad Air 2 (Wi-Fi)",
"iPad5,4": "iPad Air 2 (Cellular)",
"iPad11,3": "iPad Air (3rd generation) (2019) (Wi-Fi)",
"iPad11,4": "iPad Air (3rd generation) (2019) (Cellular)",
"iPad13,1": "iPad Air (4th generation) (2020) (Wi-Fi)",
"iPad13,2": "iPad Air (4th generation) (2020) (Cellular)",
"iPad13,16": "iPad Air (5th generation) (2022) (Wi-Fi)",
"iPad13,17": "iPad Air (5th generation) (2022) (Cellular)",
// iPad Pro
"iPad6,3": "iPad Pro 9.7\" (Wi-Fi)",
"iPad6,4": "iPad Pro 9.7\" (Cellular)",
"iPad6,7": "iPad Pro 12.9\" (Wi-Fi)",
"iPad6,8": "iPad Pro 12.9\" (Cellular)",
"iPad7,1": "iPad Pro 12.9\" (2nd generation) (Wi-Fi)",
"iPad7,2": "iPad Pro 12.9\" (2nd generation) (Cellular)",
"iPad7,3": "iPad Pro 10.5\" (Wi-Fi)",
"iPad7,4": "iPad Pro 10.5\" (Cellular)",
"iPad8,1": "iPad Pro 11\" (2018) (Wi-Fi)",
"iPad8,2": "iPad Pro 11\" (2018) (Wi-Fi, 1TB)",
"iPad8,3": "iPad Pro 11\" (2018) (Cellular)",
"iPad8,4": "iPad Pro 11\" (2018) (Cellular 1TB)",
"iPad8,5": "iPad Pro 12.9\" (3rd generation) (2018) (Wi-Fi)",
"iPad8,6": "iPad Pro 12.9\" (3rd generation) (2018) (Wi-Fi, 1TB)",
"iPad8,7": "iPad Pro 12.9\" (3rd generation) (2018) (Cellular)",
"iPad8,8": "iPad Pro 12.9\" (3rd generation) (2018) (Cellular, 1TB)",
"iPad8,9": "iPad Pro 11\" (2nd generation) (2020) (Wi-Fi)",
"iPad8,10": "iPad Pro 11\" (2nd generation) (2020) (Cellular)",
"iPad8,11": "iPad Pro 12.9\" (4th generation) (2020) (Wi-Fi)",
"iPad8,12": "iPad Pro 12.9\" (4th generation) (2020) (Cellular)",
"iPad13,4": "iPad Pro 11\" (3nd generation) (2021) (Wi-Fi)",
"iPad13,5": "iPad Pro 11\" (3nd generation) (2021) (Cellular US)",
"iPad13,6": "iPad Pro 11\" (3nd generation) (2021) (Cellular Global)",
"iPad13,7": "iPad Pro 11\" (3nd generation) (2021) (Cellular China)",
"iPad13,8": "iPad Pro 12.9\" (5th generation) (2021) (Wi-Fi)",
"iPad13,9": "iPad Pro 12.9\" (5th generation) (2021) (Cellular US)",
"iPad13,10": "iPad Pro 12.9\" (5th generation) (2021) (Cellular Global)",
"iPad13,11": "iPad Pro 12.9\" (5th generation) (2021) (Cellular China)",
"iPad14,3": "iPad Pro 11\" (4th generation) (2022) (Wi-Fi)",
"iPad14,4": "iPad Pro 11\" (4th generation) (2022) (Cellular)",
"iPad14,5": "iPad Pro 12.9\" (6th generation) (2022) (Wi-Fi)",
"iPad14,6": "iPad Pro 12.9\" (6th generation) (2022) (Cellular)",
// iPad mini
"iPad4,4": "iPad mini 2 (Wi-Fi)",
"iPad4,5": "iPad mini 2 (Cellular)",
"iPad4,6": "iPad mini 2 (China)",
"iPad4,7": "iPad mini 3 (Wi-Fi)",
"iPad4,8": "iPad mini 3 (Cellular)",
"iPad4,9": "iPad mini 3 (China)",
"iPad5,1": "iPad mini 4 (Wi-Fi)",
"iPad5,2": "iPad mini 4 (Cellular)",
"iPad11,1": "iPad mini (5th generation) (2019) (Wi-Fi)",
"iPad11,2": "iPad mini (5th generation) (2019) (Cellular)",
"iPad14,1": "iPad mini (6th generation) (2021) (Wi-Fi)",
"iPad14,2": "iPad mini (6th generation) (2021) (Cellular)",
// Apple TV
"AppleTV2,1": "Apple TV 2G",
"AppleTV3,1": "Apple TV 3",
"AppleTV3,2": "Apple TV 3 (2013)",
"AppleTV5,3": "Apple TV 4",
"AppleTV6,2": "Apple TV 4K",
"AppleTV11,1": "Apple TV 4K (2nd generation)",
// Apple Watch
"Watch1,1": "Apple Watch (1st generation) (38mm)",
"Watch1,2": "Apple Watch (1st generation) (42mm)",
"Watch2,6": "Apple Watch Series 1 (38mm)",
"Watch2,7": "Apple Watch Series 1 (42mm)",
"Watch2,3": "Apple Watch Series 2 (38mm)",
"Watch2,4": "Apple Watch Series 2 (42mm)",
"Watch3,1": "Apple Watch Series 3 (38mm Cellular)",
"Watch3,2": "Apple Watch Series 3 (42mm Cellular)",
"Watch3,3": "Apple Watch Series 3 (38mm)",
"Watch3,4": "Apple Watch Series 3 (42mm)",
"Watch4,1": "Apple Watch Series 4 (40mm)",
"Watch4,2": "Apple Watch Series 4 (44mm)",
"Watch4,3": "Apple Watch Series 4 (40mm Cellular)",
"Watch4,4": "Apple Watch Series 4 (44mm Cellular)",
"Watch5,1": "Apple Watch Series 5 (40mm)",
"Watch5,2": "Apple Watch Series 5 (44mm)",
"Watch5,3": "Apple Watch Series 5 (40mm Cellular)",
"Watch5,4": "Apple Watch Series 5 (44mm Cellular)",
"Watch6,1": "Apple Watch Series 6 (40mm)",
"Watch6,2": "Apple Watch Series 6 (44mm)",
"Watch6,3": "Apple Watch Series 6 (40mm Cellular)",
"Watch6,4": "Apple Watch Series 6 (44mm Cellular)",
"Watch5,9": "Apple Watch SE (40mm)",
"Watch5,10": "Apple Watch SE (44mm)",
"Watch5,11": "Apple Watch SE (40mm Cellular)",
"Watch5,12": "Apple Watch SE (44mm Cellular)",
"Watch6,6": "Apple Watch Series 7 (41mm)",
"Watch6,7": "Apple Watch Series 7 (45mm)",
"Watch6,8": "Apple Watch Series 7 (41mm Cellular)",
"Watch6,9": "Apple Watch Series 7 (45mm Cellular)",
"Watch6,10": "Apple Watch SE (2nd gen) (40mm)",
"Watch6,11": "Apple Watch SE (2nd gen) (44mm)",
"Watch6,12": "Apple Watch SE (2nd gen) (40mm Cellular)",
"Watch6,13": "Apple Watch SE (2nd gen) (44mm Cellular)",
"Watch6,14": "Apple Watch Series 8 (41mm)",
"Watch6,15": "Apple Watch Series 8 (45mm)",
"Watch6,16": "Apple Watch Series 8 (41mm Cellular)",
"Watch6,17": "Apple Watch Series 8 (45mm Cellular)",
"Watch6,18": "Apple Watch Ultra",
// iMac
"iMac21,1": "iMac 24\" (M1, 2021)",
"iMac21,2": "iMac 24\" (M1, 2021)",
// Mac mini
"Macmini9,1": "Mac mini (M1, 2020)",
// MacBook Air
"MacBookAir10,1": "MacBook Air (M1, Late 2020)",
// MacBook Pro
"MacBookPro17,1": "MacBook Pro 13\" (M1, 2020)",
"MacBookPro18,3": "MacBook Pro 14\" (M1 Pro, 2021)",
"MacBookPro18,4": "MacBook Pro 14\" (M1 Max, 2021)",
"MacBookPro18,1": "MacBook Pro 16\" (M1 Pro, 2021)",
"MacBookPro18,2": "MacBook Pro 16\" (M1 Max, 2021)",
// Simulator
"i386": "Simulator",
"x86_64": "Simulator",
]
return deviceMap[platform] ?? platform
}
You can test it using following code:
print("Current device is: ", self.userDeviceName())
Objective-C
I also added new devices to the Objective-C code
Don't forget to import sys/sysctl.h
#import <sys/sysctl.h>
- (NSString *) userDeviceName {
size_t size;
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
char *machine = malloc(size);
sysctlbyname("hw.machine", machine, &size, NULL, 0);
NSString *platform = [NSString stringWithCString:machine encoding:NSUTF8StringEncoding];
free(machine);
NSDictionary *deviceMap = #{
// iPhone
#"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,2": #"iPhone XS",
#"iPhone11,6": #"iPhone XS Max",
#"iPhone11,8": #"iPhone XR",
#"iPhone12,1": #"iPhone 11",
#"iPhone12,3": #"iPhone 11 Pro",
#"iPhone12,5": #"iPhone 11 Pro Max",
#"iPhone12,8": #"iPhone SE (2nd generation) (2020)",
#"iPhone13,1": #"iPhone 12 mini",
#"iPhone13,2": #"iPhone 12",
#"iPhone13,3": #"iPhone 12 Pro",
#"iPhone13,4": #"iPhone 12 Pro Max",
#"iPhone14,4": #"iPhone 13 mini",
#"iPhone14,5": #"iPhone 13",
#"iPhone14,2": #"iPhone 13 Pro",
#"iPhone14,3": #"iPhone 13 Pro Max",
#"iPhone14,6": #"iPhone SE (3rd generation) (2022)",
#"iPhone14,7": #"iPhone 14",
#"iPhone14,8": #"iPhone 14 Plus",
#"iPhone15,2": #"iPhone 14 Pro",
#"iPhone15,3": #"iPhone 14 Pro Max",
// iPod touch
#"iPod7,1": #"iPod Touch (6th generation)",
#"iPod9,1": #"iPod Touch (7th generation) (2019)",
// iPad
#"iPad3,4": #"iPad (4th generation) (Wi-Fi)",
#"iPad3,5": #"iPad (4th generation) (GSM)",
#"iPad3,6": #"iPad (4th generation) (GSM+CDMA)",
#"iPad6,11": #"iPad (5th generation) 9.7\" (2017) (Wi-Fi)",
#"iPad6,12": #"iPad (5th generation) 9.7\" (2017) (Cellular)",
#"iPad7,5": #"iPad (6th generation) 9.7\" (2018) (Wi-Fi)",
#"iPad7,6": #"iPad (6th generation) 9.7\" (2018) (Cellular)",
#"iPad7,11": #"iPad (7th generation) 10.2\" (2019) (Wi-Fi)",
#"iPad7,12": #"iPad (7th generation) 10.2\" (2019) (Cellular)",
#"iPad11,6": #"iPad (8th generation) 10.2\" (2020) (Wi-Fi)",
#"iPad11,7": #"iPad (8th generation) 10.2\" (2020) (Cellular)",
#"iPad12,1": #"iPad (9th generation) 10.2\" (2021) (Wi-Fi)",
#"iPad12,2": #"iPad (9th generation) 10.2\" (2021) (Cellular)",
#"iPad13,18": #"iPad (10th generation) 10.9\" (2022) (Wi-Fi)",
#"iPad13,19": #"iPad (10th generation) 10.9\" (2022) (Cellular)",
// iPad Air
#"iPad4,1": #"iPad Air (Wi-Fi)",
#"iPad4,2": #"iPad Air (Cellular)",
#"iPad4,3": #"iPad Air (China)",
#"iPad5,3": #"iPad Air 2 (Wi-Fi)",
#"iPad5,4": #"iPad Air 2 (Cellular)",
#"iPad11,3": #"iPad Air (3rd generation) (2019) (Wi-Fi)",
#"iPad11,4": #"iPad Air (3rd generation) (2019) (Cellular)",
#"iPad13,1": #"iPad Air (4th generation) (2020) (Wi-Fi)",
#"iPad13,2": #"iPad Air (4th generation) (2020) (Cellular)",
#"iPad13,16": #"iPad Air (5th generation) (2022) (Wi-Fi)",
#"iPad13,17": #"iPad Air (5th generation) (2022) (Cellular)",
// iPad Pro
#"iPad6,3": #"iPad Pro 9.7\" (Wi-Fi)",
#"iPad6,4": #"iPad Pro 9.7\" (Cellular)",
#"iPad6,7": #"iPad Pro 12.9\" (Wi-Fi)",
#"iPad6,8": #"iPad Pro 12.9\" (Cellular)",
#"iPad7,1": #"iPad Pro 12.9\" (2nd generation) (Wi-Fi)",
#"iPad7,2": #"iPad Pro 12.9\" (2nd generation) (Cellular)",
#"iPad7,3": #"iPad Pro 10.5\" (Wi-Fi)",
#"iPad7,4": #"iPad Pro 10.5\" (Cellular)",
#"iPad8,1": #"iPad Pro 11\" (2018) (Wi-Fi)",
#"iPad8,2": #"iPad Pro 11\" (2018) (Wi-Fi, 1TB)",
#"iPad8,3": #"iPad Pro 11\" (2018) (Cellular)",
#"iPad8,4": #"iPad Pro 11\" (2018) (Cellular 1TB)",
#"iPad8,5": #"iPad Pro 12.9\" (3rd generation) (2018) (Wi-Fi)",
#"iPad8,6": #"iPad Pro 12.9\" (3rd generation) (2018) (Wi-Fi, 1TB)",
#"iPad8,7": #"iPad Pro 12.9\" (3rd generation) (2018) (Cellular)",
#"iPad8,8": #"iPad Pro 12.9\" (3rd generation) (2018) (Cellular, 1TB)",
#"iPad8,9": #"iPad Pro 11\" (2nd generation) (2020) (Wi-Fi)",
#"iPad8,10": #"iPad Pro 11\" (2nd generation) (2020) (Cellular)",
#"iPad8,11": #"iPad Pro 12.9\" (4th generation) (2020) (Wi-Fi)",
#"iPad8,12": #"iPad Pro 12.9\" (4th generation) (2020) (Cellular)",
#"iPad13,4": #"iPad Pro 11\" (3nd generation) (2021) (Wi-Fi)",
#"iPad13,5": #"iPad Pro 11\" (3nd generation) (2021) (Cellular US)",
#"iPad13,6": #"iPad Pro 11\" (3nd generation) (2021) (Cellular Global)",
#"iPad13,7": #"iPad Pro 11\" (3nd generation) (2021) (Cellular China)",
#"iPad13,8": #"iPad Pro 12.9\" (5th generation) (2021) (Wi-Fi)",
#"iPad13,9": #"iPad Pro 12.9\" (5th generation) (2021) (Cellular US)",
#"iPad13,10": #"iPad Pro 12.9\" (5th generation) (2021) (Cellular Global)",
#"iPad13,11": #"iPad Pro 12.9\" (5th generation) (2021) (Cellular China)",
#"iPad14,3": #"iPad Pro 11\" (4th generation) (2022) (Wi-Fi)",
#"iPad14,4": #"iPad Pro 11\" (4th generation) (2022) (Cellular)",
#"iPad14,5": #"iPad Pro 12.9\" (6th generation) (2022) (Wi-Fi)",
#"iPad14,6": #"iPad Pro 12.9\" (6th generation) (2022) (Cellular)",
// iPad mini
#"iPad4,4": #"iPad mini 2 (Wi-Fi)",
#"iPad4,5": #"iPad mini 2 (Cellular)",
#"iPad4,6": #"iPad mini 2 (China)",
#"iPad4,7": #"iPad mini 3 (Wi-Fi)",
#"iPad4,8": #"iPad mini 3 (Cellular)",
#"iPad4,9": #"iPad mini 3 (China)",
#"iPad5,1": #"iPad mini 4 (Wi-Fi)",
#"iPad5,2": #"iPad mini 4 (Cellular)",
#"iPad11,1": #"iPad mini (5th generation) (2019) (Wi-Fi)",
#"iPad11,2": #"iPad mini (5th generation) (2019) (Cellular)",
#"iPad14,1": #"iPad mini (6th generation) (2021) (Wi-Fi)",
#"iPad14,2": #"iPad mini (6th generation) (2021) (Cellular)",
// Apple TV
#"AppleTV2,1": #"Apple TV 2G",
#"AppleTV3,1": #"Apple TV 3",
#"AppleTV3,2": #"Apple TV 3 (2013)",
#"AppleTV5,3": #"Apple TV 4",
#"AppleTV6,2": #"Apple TV 4K",
#"AppleTV11,1": #"Apple TV 4K (2nd generation)",
// Apple Watch
#"Watch1,1": #"Apple Watch (1st generation) (38mm)",
#"Watch1,2": #"Apple Watch (1st generation) (42mm)",
#"Watch2,6": #"Apple Watch Series 1 (38mm)",
#"Watch2,7": #"Apple Watch Series 1 (42mm)",
#"Watch2,3": #"Apple Watch Series 2 (38mm)",
#"Watch2,4": #"Apple Watch Series 2 (42mm)",
#"Watch3,1": #"Apple Watch Series 3 (38mm Cellular)",
#"Watch3,2": #"Apple Watch Series 3 (42mm Cellular)",
#"Watch3,3": #"Apple Watch Series 3 (38mm)",
#"Watch3,4": #"Apple Watch Series 3 (42mm)",
#"Watch4,1": #"Apple Watch Series 4 (40mm)",
#"Watch4,2": #"Apple Watch Series 4 (44mm)",
#"Watch4,3": #"Apple Watch Series 4 (40mm Cellular)",
#"Watch4,4": #"Apple Watch Series 4 (44mm Cellular)",
#"Watch5,1": #"Apple Watch Series 5 (40mm)",
#"Watch5,2": #"Apple Watch Series 5 (44mm)",
#"Watch5,3": #"Apple Watch Series 5 (40mm Cellular)",
#"Watch5,4": #"Apple Watch Series 5 (44mm Cellular)",
#"Watch6,1": #"Apple Watch Series 6 (40mm)",
#"Watch6,2": #"Apple Watch Series 6 (44mm)",
#"Watch6,3": #"Apple Watch Series 6 (40mm Cellular)",
#"Watch6,4": #"Apple Watch Series 6 (44mm Cellular)",
#"Watch5,9": #"Apple Watch SE (40mm)",
#"Watch5,10": #"Apple Watch SE (44mm)",
#"Watch5,11": #"Apple Watch SE (40mm Cellular)",
#"Watch5,12": #"Apple Watch SE (44mm Cellular)",
#"Watch6,6": #"Apple Watch Series 7 (41mm)",
#"Watch6,7": #"Apple Watch Series 7 (45mm)",
#"Watch6,8": #"Apple Watch Series 7 (41mm Cellular)",
#"Watch6,9": #"Apple Watch Series 7 (45mm Cellular)",
#"Watch6,10": #"Apple Watch SE (2nd gen) (40mm)",
#"Watch6,11": #"Apple Watch SE (2nd gen) (44mm)",
#"Watch6,12": #"Apple Watch SE (2nd gen) (40mm Cellular)",
#"Watch6,13": #"Apple Watch SE (2nd gen) (44mm Cellular)",
#"Watch6,14": #"Apple Watch Series 8 (41mm)",
#"Watch6,15": #"Apple Watch Series 8 (45mm)",
#"Watch6,16": #"Apple Watch Series 8 (41mm Cellular)",
#"Watch6,17": #"Apple Watch Series 8 (45mm Cellular)",
#"Watch6,18": #"Apple Watch Ultra",
// iMac
#"iMac21,1": #"iMac 24\" (M1, 2021)",
#"iMac21,2": #"iMac 24\" (M1, 2021)",
// Mac mini
#"Macmini9,1": #"Mac mini (M1, 2020)",
// MacBook Air
#"MacBookAir10,1": #"MacBook Air (M1, Late 2020)",
// MacBook Pro
#"MacBookPro17,1": #"MacBook Pro 13\" (M1, 2020)",
#"MacBookPro18,3": #"MacBook Pro 14\" (M1 Pro, 2021)",
#"MacBookPro18,4": #"MacBook Pro 14\" (M1 Max, 2021)",
#"MacBookPro18,1": #"MacBook Pro 16\" (M1 Pro, 2021)",
#"MacBookPro18,2": #"MacBook Pro 16\" (M1 Max, 2021)",
// Simulator
#"i386": #"Simulator",
#"x86_64": #"Simulator",
};
return deviceMap[platform] ? deviceMap[platform] : platform;
}
You can test it using following code:
NSLog(#"Current device is: %#", [self userDeviceName]);

if([UIDevice currentDevice].userInterfaceIdiom==UIUserInterfaceIdiomPad) {
//Device is ipad
}else{
//Device is iphone
}

Updated platform strings for iPad Air 2 and iPad mini 3:
- (NSString *)platformString
{
NSString *platform = [self platform];
if ([platform isEqualToString:#"iPhone1,1"]) return #"iPhone 1G";
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,3"]) return #"Verizon iPhone 4";
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,1"]) return #"iPhone 6 Plus";
if ([platform isEqualToString:#"iPhone7,2"]) return #"iPhone 6";
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";
if ([platform isEqualToString:#"iPad2,1"]) return #"iPad 2 (WiFi)";
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 (WiFi)";
if ([platform isEqualToString:#"iPad2,5"]) return #"iPad Mini (WiFi)";
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 3 (WiFi)";
if ([platform isEqualToString:#"iPad3,2"]) return #"iPad 3 (GSM+CDMA)";
if ([platform isEqualToString:#"iPad3,3"]) return #"iPad 3 (GSM)";
if ([platform isEqualToString:#"iPad3,4"]) return #"iPad 4 (WiFi)";
if ([platform isEqualToString:#"iPad3,5"]) return #"iPad 4 (GSM)";
if ([platform isEqualToString:#"iPad3,6"]) return #"iPad 4 (GSM+CDMA)";
if ([platform isEqualToString:#"iPad4,1"]) return #"iPad Air (WiFi)";
if ([platform isEqualToString:#"iPad4,2"]) return #"iPad Air (Cellular)";
if ([platform isEqualToString:#"iPad4,4"]) return #"iPad mini 2G (WiFi)";
if ([platform isEqualToString:#"iPad4,5"]) return #"iPad mini 2G (Cellular)";
if ([platform isEqualToString:#"iPad4,7"]) return #"iPad mini 3 (WiFi)";
if ([platform isEqualToString:#"iPad4,8"]) return #"iPad mini 3 (Cellular)";
if ([platform isEqualToString:#"iPad4,9"]) return #"iPad mini 3 (China Model)";
if ([platform isEqualToString:#"iPad5,3"]) return #"iPad Air 2 (WiFi)";
if ([platform isEqualToString:#"iPad5,4"]) return #"iPad Air 2 (Cellular)";
if ([platform isEqualToString:#"iPad6,8"]) return #"iPad Pro";
if ([platform isEqualToString:#"i386"]) return #"Simulator";
if ([platform isEqualToString:#"x86_64"]) return #"Simulator";
return platform;
}

More usable
#include <sys/types.h>
#include <sys/sysctl.h>
#interface UIDevice(Hardware)
- (NSString *) platform;
- (BOOL)hasRetinaDisplay;
- (BOOL)hasMultitasking;
- (BOOL)hasCamera;
#end
#implementation UIDevice(Hardware)
- (NSString *) platform{
int mib[2];
size_t len;
char *machine;
mib[0] = CTL_HW;
mib[1] = HW_MACHINE;
sysctl(mib, 2, NULL, &len, NULL, 0);
machine = malloc(len);
sysctl(mib, 2, machine, &len, NULL, 0);
NSString *platform = [NSString stringWithCString:machine encoding:NSASCIIStringEncoding];
free(machine);
return platform;
}
- (BOOL)hasRetinaDisplay {
NSString *platform = [self platform];
BOOL ret = YES;
if ([platform isEqualToString:#"iPhone1,1"]) {
ret = NO;
}
else
if ([platform isEqualToString:#"iPhone1,2"]) ret = NO;
else
if ([platform isEqualToString:#"iPhone2,1"]) ret = NO;
else
if ([platform isEqualToString:#"iPod1,1"]) ret = NO;
else
if ([platform isEqualToString:#"iPod2,1"]) ret = NO;
else
if ([platform isEqualToString:#"iPod3,1"]) ret = NO;
return ret;
}
- (BOOL)hasMultitasking {
if ([self respondsToSelector:#selector(isMultitaskingSupported)]) {
return [self isMultitaskingSupported];
}
return NO;
}
- (BOOL)hasCamera {
BOOL ret = NO;
// check camera availability
return ret;
}
#end
you can reading properties with
NSLog(#"platform %#, retita %#, multitasking %#", [[UIDevice currentDevice] platform], [[UIDevice currentDevice] hasRetinaDisplay] ? #"YES" : #"NO" , [[UIDevice currentDevice] hasMultitasking] ? #"YES" : #"NO");

Here's a minor update with new models:
- (NSString *) platformString{
NSString *platform = [self platform];
if ([platform isEqualToString:#"iPhone1,1"]) return #"iPhone 1G";
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:#"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:#"i386"]) return #"iPhone Simulator";
return platform;
}

I know an answer has been ticked already, but for future reference, you could always use the device screen size to figure out which device it is like so:
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
CGSize result = [[UIScreen mainScreen] bounds].size;
if (result.height == 480) {
// 3.5 inch display - iPhone 4S and below
NSLog(#"Device is an iPhone 4S or below");
}
else if (result.height == 568) {
// 4 inch display - iPhone 5
NSLog(#"Device is an iPhone 5/S/C");
}
else if (result.height == 667) {
// 4.7 inch display - iPhone 6
NSLog(#"Device is an iPhone 6");
}
else if (result.height == 736) {
// 5.5 inch display - iPhone 6 Plus
NSLog(#"Device is an iPhone 6 Plus");
}
}
else if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
// iPad 9.7 or 7.9 inch display.
NSLog(#"Device is an iPad.");
}

Just adding the iPhone 4S device code to this thread...
The iPhone 4S will return the string #"iPhone4,1".

How about this code, if new version was released, you will identifier with the last know device
- (NSString *)getModel {
size_t size;
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
char *model = malloc(size);
sysctlbyname("hw.machine", model, &size, NULL, 0);
NSString *sDeviceModel = [NSString stringWithCString:model encoding:NSUTF8StringEncoding];
free(model);
if ([sDeviceModel isEqual:#"i386"]) return #"Simulator"; //iPhone Simulator
if ([sDeviceModel isEqual:#"iPhone1,1"]) return #"iPhone1G"; //iPhone 1G
if ([sDeviceModel isEqual:#"iPhone1,2"]) return #"iPhone3G"; //iPhone 3G
if ([sDeviceModel isEqual:#"iPhone2,1"]) return #"iPhone3GS"; //iPhone 3GS
if ([sDeviceModel isEqual:#"iPhone3,1"]) return #"iPhone3GS"; //iPhone 4 - AT&T
if ([sDeviceModel isEqual:#"iPhone3,2"]) return #"iPhone3GS"; //iPhone 4 - Other carrier
if ([sDeviceModel isEqual:#"iPhone3,3"]) return #"iPhone4"; //iPhone 4 - Other carrier
if ([sDeviceModel isEqual:#"iPhone4,1"]) return #"iPhone4S"; //iPhone 4S
if ([sDeviceModel isEqual:#"iPod1,1"]) return #"iPod1stGen"; //iPod Touch 1G
if ([sDeviceModel isEqual:#"iPod2,1"]) return #"iPod2ndGen"; //iPod Touch 2G
if ([sDeviceModel isEqual:#"iPod3,1"]) return #"iPod3rdGen"; //iPod Touch 3G
if ([sDeviceModel isEqual:#"iPod4,1"]) return #"iPod4thGen"; //iPod Touch 4G
if ([sDeviceModel isEqual:#"iPad1,1"]) return #"iPadWiFi"; //iPad Wifi
if ([sDeviceModel isEqual:#"iPad1,2"]) return #"iPad3G"; //iPad 3G
if ([sDeviceModel isEqual:#"iPad2,1"]) return #"iPad2"; //iPad 2 (WiFi)
if ([sDeviceModel isEqual:#"iPad2,2"]) return #"iPad2"; //iPad 2 (GSM)
if ([sDeviceModel isEqual:#"iPad2,3"]) return #"iPad2"; //iPad 2 (CDMA)
NSString *aux = [[sDeviceModel componentsSeparatedByString:#","] objectAtIndex:0];
//If a newer version exist
if ([aux rangeOfString:#"iPhone"].location!=NSNotFound) {
int version = [[aux stringByReplacingOccurrencesOfString:#"iPhone" withString:#""] intValue];
if (version == 3) return #"iPhone4"
if (version >= 4) return #"iPhone4s";
}
if ([aux rangeOfString:#"iPod"].location!=NSNotFound) {
int version = [[aux stringByReplacingOccurrencesOfString:#"iPod" withString:#""] intValue];
if (version >=4) return #"iPod4thGen";
}
if ([aux rangeOfString:#"iPad"].location!=NSNotFound) {
int version = [[aux stringByReplacingOccurrencesOfString:#"iPad" withString:#""] intValue];
if (version ==1) return #"iPad3G";
if (version >=2) return #"iPad2";
}
//If none was found, send the original string
return sDeviceModel;
}

Adding to Arash's code, I don't care for my app what model I'm using, I just want to know what kind of device, so, I can test as follows:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
NSLog(#"I'm definitely an iPad");
} else {
NSString *deviceType = [UIDevice currentDevice].model;
if([deviceType rangeOfString:#"iPhone"].location!=NSNotFound)
{
NSLog(#"I must be an iPhone");
} else {
NSLog(#"I think I'm an iPod");
}
}

Based on the very good answers above, here is what I came up with. This is very similar to #Rodrigo's answer, but addresses #Oliver's concern from the comment on that answer. This also provides the option of including the model string in the output string.
+ (NSString *) deviceModel {
size_t size;
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
char *model = malloc(size);
sysctlbyname("hw.machine", model, &size, NULL, 0);
NSString *deviceModel = [NSString stringWithCString:model encoding:NSUTF8StringEncoding];
free(model);
return deviceModel;
}
+ (NSString *) deviceName {
NSString *deviceModel = [DeviceGateway deviceModel];
if ([deviceModel isEqual:#"i386"]) return #"Simulator"; //iPhone Simulator
if ([deviceModel isEqual:#"iPhone1,1"]) return #"iPhone1G"; //iPhone 1G
if ([deviceModel isEqual:#"iPhone1,2"]) return #"iPhone3G"; //iPhone 3G
if ([deviceModel isEqual:#"iPhone2,1"]) return #"iPhone3GS"; //iPhone 3GS
if ([deviceModel isEqual:#"iPhone3,1"]) return #"iPhone4"; //iPhone 4 - AT&T
if ([deviceModel isEqual:#"iPhone3,2"]) return #"iPhone4"; //iPhone 4 - Other carrier
if ([deviceModel isEqual:#"iPhone3,3"]) return #"iPhone4"; //iPhone 4 - Other carrier
if ([deviceModel isEqual:#"iPhone4,1"]) return #"iPhone4S"; //iPhone 4S
if ([deviceModel isEqual:#"iPod1,1"]) return #"iPod1stGen"; //iPod Touch 1G
if ([deviceModel isEqual:#"iPod2,1"]) return #"iPod2ndGen"; //iPod Touch 2G
if ([deviceModel isEqual:#"iPod3,1"]) return #"iPod3rdGen"; //iPod Touch 3G
if ([deviceModel isEqual:#"iPod4,1"]) return #"iPod4thGen"; //iPod Touch 4G
if ([deviceModel isEqual:#"iPad1,1"]) return #"iPadWiFi"; //iPad Wifi
if ([deviceModel isEqual:#"iPad1,2"]) return #"iPad3G"; //iPad 3G
if ([deviceModel isEqual:#"iPad2,1"]) return #"iPad2"; //iPad 2 (WiFi)
if ([deviceModel isEqual:#"iPad2,2"]) return #"iPad2"; //iPad 2 (GSM)
if ([deviceModel isEqual:#"iPad2,3"]) return #"iPad2"; //iPad 2 (CDMA)
NSString *aux = [[deviceModel componentsSeparatedByString:#","] objectAtIndex:0];
//If a newer version exists
if ([aux rangeOfString:#"iPhone"].location != NSNotFound) {
int version = [[aux stringByReplacingOccurrencesOfString:#"iPhone" withString:#""] intValue];
if (version == 3) return #"iPhone4";
if (version == 4) return #"iPhone4s";
return #"Newer iPhone";
}
if ([aux rangeOfString:#"iPod"].location != NSNotFound) {
int version = [[aux stringByReplacingOccurrencesOfString:#"iPod" withString:#""] intValue];
if (version == 4) return #"iPod4thGen";
return #"Newer iPod";
}
if ([aux rangeOfString:#"iPad"].location != NSNotFound) {
int version = [[aux stringByReplacingOccurrencesOfString:#"iPad" withString:#""] intValue];
if (version == 1) return #"iPad3G";
if (version == 2) return #"iPad2";
return #"Newer iPad";
}
//If none was found, send the original string
return deviceModel;
}
+ (NSString *) deviceNameWithDeviceModel:(BOOL)shouldIncludeDeviceModel {
if (shouldIncludeDeviceModel) {
return [NSString stringWithFormat:#"%# (%#)", [DeviceGateway deviceName], [DeviceGateway deviceModel]];
}
return [DeviceGateway deviceName];
}

There's a pretty mature library (by me) for that called SDVersion.
You can check for running device's model, screen size and many other parameters. It also supports OSX.
Example:
// Check for device model
if ([SDVersion deviceVersion] == iPhone6)
NSLog(#"You got the iPhone 6. Sweet 🍭!");
else if ([SDVersion deviceVersion] == iPhone6Plus)
NSLog(#"iPhone 6 Plus? Bigger is better!");
else if ([SDVersion deviceVersion] == iPadAir2)
NSLog(#"You own an iPad Air 2 🌀!");
// Check for device screen size
if ([SDVersion deviceSize] == Screen4inch)
NSLog(#"Your screen is 4 inches");

NSString *deviceType = [UIDevice currentDevice].model;

#import <sys/utsname.h>
NSString *iPhone = [self iPhoneVersion];
-(NSString*)iPhoneVersion
{
NSString *platform;
struct utsname systemInfo;
uname(&systemInfo);
platform = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
if ([platform isEqualToString:#"iPhone1,1"]) return #"iPhone 1G";
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,3"]) return #"VerizoniPhone 4";
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:#"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";
if ([platform isEqualToString:#"iPad2,1"]) return #"iPad 2 (WiFi)";
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 (WiFi)";
if ([platform isEqualToString:#"iPad2,5"]) return #"iPad Mini (WiFi)";
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 3 (WiFi)";
if ([platform isEqualToString:#"iPad3,2"]) return #"iPad 3 (GSM+CDMA)";
if ([platform isEqualToString:#"iPad3,3"]) return #"iPad 3 (GSM)";
if ([platform isEqualToString:#"iPad3,4"]) return #"iPad 4 (WiFi)";
if ([platform isEqualToString:#"iPad3,5"]) return #"iPad 4 (GSM)";
if ([platform isEqualToString:#"iPad3,6"]) return #"iPad 4 (GSM+CDMA)";
if ([platform isEqualToString:#"iPad4,1"]) return #"iPad Air (WiFi)";
if ([platform isEqualToString:#"iPad4,2"]) return #"iPad Air (Cellular)";
if ([platform isEqualToString:#"iPad4,3"]) return #"iPad Air";
if ([platform isEqualToString:#"iPad4,4"]) return #"iPad Mini 2G (WiFi)";
if ([platform isEqualToString:#"iPad4,5"]) return #"iPad Mini 2G (Cellular)";
if ([platform isEqualToString:#"iPad4,6"]) return #"iPad Mini 2G";
if ([platform isEqualToString:#"iPad4,7"]) return #"iPad Mini 3 (WiFi)";
if ([platform isEqualToString:#"iPad4,8"]) return #"iPad Mini 3 (Cellular)";
if ([platform isEqualToString:#"iPad4,9"]) return #"iPad Mini 3 (China)";
if ([platform isEqualToString:#"iPad5,3"]) return #"iPad Air 2 (WiFi)";
if ([platform isEqualToString:#"iPad5,4"]) return #"iPad Air 2 (Cellular)";
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:#"i386"]) return #"Simulator";
if ([platform isEqualToString:#"x86_64"]) return #"Simulator";
return platform;
}

I took it a bit further and converted the big "isEqualToString" block into a classification of bit masks for the device type, the generation, and that other qualifier after the comma (I'm calling it the sub generation). It is wrapped in a class with a singleton call SGPlatform which avoids a lot of repetitive string operations. Code is available https://github.com/danloughney/spookyGroup
The class lets you do things like this:
if ([SGPlatform iPad] && [SGPlatform generation] > 3) {
// set for high performance
}
and
switch ([SGPlatform deviceMask]) {
case DEVICE_IPHONE:
break;
case DEVICE_IPAD:
break;
case DEVICE_IPAD_MINI:
break;
}
The classification of the devices is in the platformBits method. That method should be very familiar to the readers of this thread. I have classified the devices by their type and generation because I'm mostly interested in the overall performance, but the source can be tweaked to provide any classification that you are interested in, retina screen, networking capabilities, etc..

Below mentioned code snippet should help :
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
// iPhone device
}
else if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
// iPad device
}
else {
// Other device i.e. iPod
}

- (BOOL)deviceiPhoneOriPod
{
NSString *deviceType = [UIDevice currentDevice].model;
if([deviceType rangeOfString:#"iPhone"].location!=NSNotFound)
return YES;
else
return NO;
}

Dutchie432 and Brian Robbins have provided great solutions. But there's still one model missing, the Verizon iPhone 4. Here's the missing line.
if ([platform isEqualToString:#"iPhone3,2"]) return #"iPhone 4"; //Verizon

I like Erica Sadun's stuff. She includes AppleTV devices and others you might not think of.
https://github.com/erica/uidevice-extension/blob/master/UIDevice-Hardware.h

The possible vales of
[[UIDevice currentDevice] model];
are iPod touch, iPhone, iPhone Simulator, iPad, iPad Simulator
If you want to know which hardware iOS is ruining on like iPhone3, iPhone4, iPhone5 etc below is the code for that
NOTE: The below code may not contain all device's string, I'm with other guys are maintaining the same code on GitHub so please take the latest code from there
Objective-C : GitHub/DeviceUtil
Swift : GitHub/DeviceGuru
#include <sys/types.h>
#include <sys/sysctl.h>
- (NSString*)hardwareDescription {
NSString *hardware = [self hardwareString];
if ([hardware isEqualToString:#"iPhone1,1"]) return #"iPhone 2G";
if ([hardware isEqualToString:#"iPhone1,2"]) return #"iPhone 3G";
if ([hardware isEqualToString:#"iPhone3,1"]) return #"iPhone 4";
if ([hardware isEqualToString:#"iPhone4,1"]) return #"iPhone 4S";
if ([hardware isEqualToString:#"iPhone5,1"]) return #"iPhone 5";
if ([hardware isEqualToString:#"iPod1,1"]) return #"iPodTouch 1G";
if ([hardware isEqualToString:#"iPod2,1"]) return #"iPodTouch 2G";
if ([hardware isEqualToString:#"iPad1,1"]) return #"iPad";
if ([hardware isEqualToString:#"iPad2,6"]) return #"iPad Mini";
if ([hardware isEqualToString:#"iPad4,1"]) return #"iPad Air WIFI";
//there are lots of other strings too, checkout the github repo
//link is given at the top of this answer
if ([hardware isEqualToString:#"i386"]) return #"Simulator";
if ([hardware isEqualToString:#"x86_64"]) return #"Simulator";
return nil;
}
- (NSString*)hardwareString {
size_t size = 100;
char *hw_machine = malloc(size);
int name[] = {CTL_HW,HW_MACHINE};
sysctl(name, 2, hw_machine, &size, NULL, 0);
NSString *hardware = [NSString stringWithUTF8String:hw_machine];
free(hw_machine);
return hardware;
}

Answer in Swift 3,
struct DeviceInformation {
// UIDevice.current.model's value is "iPhone" or "iPad",which does not include details; the following "model" is detailed, such as, iPhone7,1 is actually iPhone 6 plus
static let model: String = {
var size = 0
sysctlbyname("hw.machine", nil, &size, nil, 0)
var machine = [CChar](repeating: 0, count: Int(size))
sysctlbyname("hw.machine", &machine, &size, nil, 0)
return String(cString: machine)
}()
static let uuid = UIDevice.current.identifierForVendor?.uuidString ?? ""
static let idForAdService = ASIdentifierManager.shared().advertisingIdentifier.uuidString
static func diviceTypeReadableName() -> String {
switch model {
case "iPhone1,1": return "iPhone 1G"
case "iPhone1,2": return "iPhone 3G"
case "iPhone2,1": return "iPhone 3GS"
case "iPhone3,1": return "iPhone 4"
case "iPhone3,3": return "iPhone 4 (Verizon)"
case "iPhone4,1": return "iPhone 4S"
case "iPhone5,1": return "iPhone 5 (GSM)"
case "iPhone5,2": return "iPhone 5 (GSM+CDMA)"
case "iPhone5,3": return "iPhone 5c (GSM)"
case "iPhone5,4": return "iPhone 5c (GSM+CDMA)"
case "iPhone6,1": return "iPhone 5s (GSM)"
case "iPhone6,2": return "iPhone 5s (GSM+CDMA)"
case "iPhone7,2": return "iPhone 6"
case "iPhone7,1": return "iPhone 6 Plus"
case "iPhone8,1": return "iPhone 6s"
case "iPhone8,2": return "iPhone 6s Plus"
case "iPhone8,4": return "iPhone SE"
case "iPhone9,1": return "iPhone 7"
case "iPhone9,3": return "iPhone 7"
case "iPhone9,2": return "iPhone 7 Plus"
case "iPhone9,4": return "iPhone 7 Plus"
case "iPod1,1": return "iPod Touch 1G"
case "iPod2,1": return "iPod Touch 2G"
case "iPod3,1": return "iPod Touch 3G"
case "iPod4,1": return "iPod Touch 4G"
case "iPod5,1": return "iPod Touch 5G"
case "iPod7,1": return "iPod Touch 6G"
case "iPad1,1": return "iPad 1G"
case "iPad2,1": return "iPad 2 (Wi-Fi)"
case "iPad2,2": return "iPad 2 (GSM)"
case "iPad2,3": return "iPad 2 (CDMA)"
case "iPad2,4": return "iPad 2 (Wi-Fi)"
case "iPad2,5": return "iPad Mini (Wi-Fi)"
case "iPad2,6": return "iPad Mini (GSM)"
case "iPad2,7": return "iPad Mini (GSM+CDMA)"
case "iPad3,1": return "iPad 3 (Wi-Fi)"
case "iPad3,2": return "iPad 3 (GSM+CDMA)"
case "iPad3,3": return "iPad 3 (GSM)"
case "iPad3,4": return "iPad 4 (Wi-Fi)"
case "iPad3,5": return "iPad 4 (GSM)"
case "iPad3,6": return "iPad 4 (GSM+CDMA)"
case "iPad4,1": return "iPad Air (Wi-Fi)"
case "iPad4,2": return "iPad Air (Cellular)"
case "iPad4,3": return "iPad Air (China)"
case "iPad4,4": return "iPad Mini 2G (Wi-Fi)"
case "iPad4,5": return "iPad Mini 2G (Cellular)"
case "iPad4,6": return "iPad Mini 2G (China)"
case "iPad4,7": return "iPad Mini 3 (Wi-Fi)"
case "iPad4,8": return "iPad Mini 3 (Cellular)"
case "iPad4,9": return "iPad Mini 3 (China)"
case "iPad5,1": return "iPad Mini 4 (Wi-Fi)"
case "iPad5,2": return "iPad Mini 4 (Cellular)"
case "iPad5,3": return "iPad Air 2 (Wi-Fi)"
case "iPad5,4": return "iPad Air 2 (Cellular)"
case "iPad6,3": return "iPad Pro 9.7' (Wi-Fi)"
case "iPad6,4": return "iPad Pro 9.7' (Cellular)"
case "iPad6,7": return "iPad Pro 12.9' (Wi-Fi)"
case "iPad6,8": return "iPad Pro 12.9' (Cellular)"
case "AppleTV2,1": return "Apple TV 2G"
case "AppleTV3,1": return "Apple TV 3"
case "AppleTV3,2": return "Apple TV 3 (2013)"
case "AppleTV5,3": return "Apple TV 4"
case "Watch1,1": return "Apple Watch Series 1 (38mm, S1)"
case "Watch1,2": return "Apple Watch Series 1 (42mm, S1)"
case "Watch2,6": return "Apple Watch Series 1 (38mm, S1P)"
case "Watch2,7": return "Apple Watch Series 1 (42mm, S1P)"
case "Watch2,3": return "Apple Watch Series 2 (38mm, S2)"
case "Watch2,4": return "Apple Watch Series 2 (42mm, S2)"
case "i386": return "Simulator"
case "x86_64": return "Simulator"
default:
return ""
}
}
}

For simple comparison I always like macro:
#define IS_IPOD [[UIDevice currentDevice].model containsString:#"iPod"]
#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
It's simple and easy to use.

I'd like to add that to retrieve the front and enclosure color of the device there's a private API:
UIDevice *device = [UIDevice currentDevice];
SEL selector = NSSelectorFromString([device.systemVersion hasPrefix:#"7"] ? #"_deviceInfoForKey:" : #"deviceInfoForKey:");
if ([device respondsToSelector:selector]) {
NSLog(#"DeviceColor: %# DeviceEnclosureColor: %#", [device performSelector:selector withObject:#"DeviceColor"], [device performSelector:selector withObject:#"DeviceEnclosureColor"]);
}
I've blogged about this and provide a sample app:
http://www.futuretap.com/blog/device-colors/

NSString *deviceType = [[UIDevice currentDevice] systemName];
I can assure that the above suggested one will work in iOS 7 and above. I believe it will work in iOS 6 too. But am not sure about that.

You can check GBDeviceInfo on GitHub, also available via CocoaPods. It provides simple API for detecting various properties with support of all latest devices:
Device family
[GBDeviceInfo deviceDetails].family == GBDeviceFamilyiPhone;
Device model
[GBDeviceInfo deviceDetails].model == GBDeviceModeliPhone6.
For more see Readme.

To identifiy iPhone 4S, simply check the following:
var isIphone4S: Bool {
let width = UIScreen.main.bounds.size.width
let height = UIScreen.main.bounds.size.height
let proportions = width > height ? width / height : height / width
return proportions == 1.5 && UIDevice.current.model == "iPhone"
}

I've created an extension that lets you to have 3 levels of identification:
type of device
type of iPhone/iPad by inch
model of device
It updates with last iOS devices
UIDeviceDetector

Related

iOS Core Bluetooth not working on Bluetooth 5.0 Devices (iPhone X, iPhone 8, iPhone 8 Plus)

I'm working on BLE, my code run perfectly on bluetooth 4.2 devices (iPhone SE, iPhone 6, iPhone 6 Plus, iPhone 7). When I switch to on Bluetooth 5.0 devices(iPhone X, iPhone 8 Plus), my code will stop at didDiscoverPeripheral function, will not get into didConnectPeripheral function.
- (void) centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI {
if ([peripheral.name isEqualToString:bleDic[#"name"]]) {
self.connectedPeripheral = peripheral;
self.connectedPeripheral.delegate = self;
[self.cm connectPeripheral:self.connectedPeripheral options:nil];
}
}
- (void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral {
[self.connectedPeripheral discoverServices:#[[CBUUID UUIDWithString:ServiceUUID]]];
}

How can I get the device name? ("iPhone" vs "iPad" vs "iPod" vs future) [duplicate]

Is there a way to determine the device running an application. I want to distinguish between iPhone and iPod Touch, if possible.
You can use the UIDevice class like this:
NSString *deviceType = [UIDevice currentDevice].model;
if([deviceType isEqualToString:#"iPhone"])
// it's an iPhone
This is an update for UIDeviceHardware.m from the answer above.
- (NSString *)platformString
{
NSString *platform = [self platform];
if ([platform isEqualToString:#"iPhone1,1"]) return #"iPhone 1G";
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,3"]) return #"Verizon iPhone 4";
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,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:#"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:#"iPad1,1"]) return #"iPad";
if ([platform isEqualToString:#"iPad2,1"]) return #"iPad 2 (WiFi)";
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 (WiFi)";
if ([platform isEqualToString:#"iPad2,5"]) return #"iPad Mini (WiFi)";
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 3 (WiFi)";
if ([platform isEqualToString:#"iPad3,2"]) return #"iPad 3 (GSM+CDMA)";
if ([platform isEqualToString:#"iPad3,3"]) return #"iPad 3 (GSM)";
if ([platform isEqualToString:#"iPad3,4"]) return #"iPad 4 (WiFi)";
if ([platform isEqualToString:#"iPad3,5"]) return #"iPad 4 (GSM)";
if ([platform isEqualToString:#"iPad3,6"]) return #"iPad 4 (GSM+CDMA)";
if ([platform isEqualToString:#"iPad4,1"]) return #"iPad Air (WiFi)";
if ([platform isEqualToString:#"iPad4,2"]) return #"iPad Air (Cellular)";
if ([platform isEqualToString:#"iPad4,4"]) return #"iPad mini 2G (WiFi)";
if ([platform isEqualToString:#"iPad4,5"]) return #"iPad mini 2G (Cellular)";
if ([platform isEqualToString:#"iPad5,1"]) return #"iPad mini 4 (WiFi)";
if ([platform isEqualToString:#"iPad5,2"]) return #"iPad mini 4 (Cellular)";
if ([platform isEqualToString:#"iPad5,3"]) return #"iPad Air 2 (WiFi)";
if ([platform isEqualToString:#"iPad5,4"]) return #"iPad Air 2 (Cellular)";
if ([platform isEqualToString:#"iPad6,3"]) return #"iPad Pro 9.7 inch (WiFi)";
if ([platform isEqualToString:#"iPad6,4"]) return #"iPad Pro 9.7 inch (Cellular)";
if ([platform isEqualToString:#"iPad6,7"]) return #"iPad Pro 12.9 inch (WiFi)";
if ([platform isEqualToString:#"iPad6,8"]) return #"iPad Pro 12.9 inch (Cellular)";
if ([platform isEqualToString:#"i386"]) return #"Simulator";
if ([platform isEqualToString:#"x86_64"]) return #"Simulator";
return platform;
}
Please feel free to use this class (gist # github)
CODE REMOVED AND RELOCATED TO
https://gist.github.com/1323251
UPDATE (01/14/11)
Obviously, this code is a bit out of date by now, but it can certainly be updated using the code on this thread provided by Brian Robbins which includes similar code with updated models. Thanks for the support on this thread.
I use this in my app. Up to date as of December 2012.
- (NSString *) platformString {
// Gets a string with the device model
size_t size;
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
char *machine = malloc(size);
sysctlbyname("hw.machine", machine, &size, NULL, 0);
NSString *platform = [NSString stringWithCString:machine encoding:NSUTF8StringEncoding];
free(machine);
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 (CDMA)";
if ([platform isEqualToString:#"iPhone4,1"]) return #"iPhone 4S";
if ([platform isEqualToString:#"iPhone5,1"]) return #"iPhone 5";
if ([platform isEqualToString:#"iPhone5,2"]) return #"iPhone 5 (GSM+CDMA)";
if ([platform isEqualToString:#"iPod1,1"]) return #"iPod Touch (1 Gen)";
if ([platform isEqualToString:#"iPod2,1"]) return #"iPod Touch (2 Gen)";
if ([platform isEqualToString:#"iPod3,1"]) return #"iPod Touch (3 Gen)";
if ([platform isEqualToString:#"iPod4,1"]) return #"iPod Touch (4 Gen)";
if ([platform isEqualToString:#"iPod5,1"]) return #"iPod Touch (5 Gen)";
if ([platform isEqualToString:#"iPad1,1"]) return #"iPad";
if ([platform isEqualToString:#"iPad1,2"]) return #"iPad 3G";
if ([platform isEqualToString:#"iPad2,1"]) return #"iPad 2 (WiFi)";
if ([platform isEqualToString:#"iPad2,2"]) return #"iPad 2";
if ([platform isEqualToString:#"iPad2,3"]) return #"iPad 2 (CDMA)";
if ([platform isEqualToString:#"iPad2,4"]) return #"iPad 2";
if ([platform isEqualToString:#"iPad2,5"]) return #"iPad Mini (WiFi)";
if ([platform isEqualToString:#"iPad2,6"]) return #"iPad Mini";
if ([platform isEqualToString:#"iPad2,7"]) return #"iPad Mini (GSM+CDMA)";
if ([platform isEqualToString:#"iPad3,1"]) return #"iPad 3 (WiFi)";
if ([platform isEqualToString:#"iPad3,2"]) return #"iPad 3 (GSM+CDMA)";
if ([platform isEqualToString:#"iPad3,3"]) return #"iPad 3";
if ([platform isEqualToString:#"iPad3,4"]) return #"iPad 4 (WiFi)";
if ([platform isEqualToString:#"iPad3,5"]) return #"iPad 4";
if ([platform isEqualToString:#"iPad3,6"]) return #"iPad 4 (GSM+CDMA)";
if ([platform isEqualToString:#"i386"]) return #"Simulator";
if ([platform isEqualToString:#"x86_64"]) return #"Simulator";
return platform;
}
Latest update - February 2023: Added iPhone 14, iPhone 14 Plus, iPhone 14 Pro, iPhone 14 Pro Max, iPad (10th generation), iPad Pro 11" (4rd generation), iPad Pro 12,9" (6th generation), Apple Watch Series 8, Apple Watch Ultra, Apple Watch SE (2nd generation).
Removed devices that don't support iOS 10
Swift
(Tested on Swift 5, Swift 4, Swift 3)
The function below returns a string with current device name.
func userDeviceName() -> String {
let platform: String = {
var size = 0
sysctlbyname("hw.machine", nil, &size, nil, 0)
var machine = [CChar](repeating: 0, count: Int(size))
sysctlbyname("hw.machine", &machine, &size, nil, 0)
return String(cString: machine)
}()
let deviceMap = [
// iPhone
"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,2": "iPhone XS",
"iPhone11,6": "iPhone XS Max",
"iPhone11,8": "iPhone XR",
"iPhone12,1": "iPhone 11",
"iPhone12,3": "iPhone 11 Pro",
"iPhone12,5": "iPhone 11 Pro Max",
"iPhone12,8": "iPhone SE (2nd generation)",
"iPhone13,1": "iPhone 12 mini",
"iPhone13,2": "iPhone 12",
"iPhone13,3": "iPhone 12 Pro",
"iPhone13,4": "iPhone 12 Pro Max",
"iPhone14,4": "iPhone 13 mini",
"iPhone14,5": "iPhone 13",
"iPhone14,2": "iPhone 13 Pro",
"iPhone14,3": "iPhone 13 Pro Max",
"iPhone14,6": "iPhone SE (3rd generation) (2022)",
"iPhone14,7": "iPhone 14",
"iPhone14,8": "iPhone 14 Plus",
"iPhone15,2": "iPhone 14 Pro",
"iPhone15,3": "iPhone 14 Pro Max",
// iPod touch
"iPod7,1": "iPod Touch (6th generation)",
"iPod9,1": "iPod Touch (7th generation) (2019)",
// iPad
"iPad3,4": "iPad (4th generation) (Wi-Fi)",
"iPad3,5": "iPad (4th generation) (GSM)",
"iPad3,6": "iPad (4th generation) (GSM+CDMA)",
"iPad6,11": "iPad (5th generation) 9.7\" (2017) (Wi-Fi)",
"iPad6,12": "iPad (5th generation) 9.7\" (2017) (Cellular)",
"iPad7,5": "iPad (6th generation) 9.7\" (2018) (Wi-Fi)",
"iPad7,6": "iPad (6th generation) 9.7\" (2018) (Cellular)",
"iPad7,11": "iPad (7th generation) 10.2\" (2019) (Wi-Fi)",
"iPad7,12": "iPad (7th generation) 10.2\" (2019) (Cellular)",
"iPad11,6": "iPad (8th generation) 10.2\" (2020) (Wi-Fi)",
"iPad11,7": "iPad (8th generation) 10.2\" (2020) (Cellular)",
"iPad12,1": "iPad (9th generation) 10.2\" (2021) (Wi-Fi)",
"iPad12,2": "iPad (9th generation) 10.2\" (2021) (Cellular)",
"iPad13,18": "iPad (10th generation) 10.9\" (2022) (Wi-Fi)",
"iPad13,19": "iPad (10th generation) 10.9\" (2022) (Cellular)",
// iPad Air
"iPad4,1": "iPad Air (Wi-Fi)",
"iPad4,2": "iPad Air (Cellular)",
"iPad4,3": "iPad Air (China)",
"iPad5,3": "iPad Air 2 (Wi-Fi)",
"iPad5,4": "iPad Air 2 (Cellular)",
"iPad11,3": "iPad Air (3rd generation) (2019) (Wi-Fi)",
"iPad11,4": "iPad Air (3rd generation) (2019) (Cellular)",
"iPad13,1": "iPad Air (4th generation) (2020) (Wi-Fi)",
"iPad13,2": "iPad Air (4th generation) (2020) (Cellular)",
"iPad13,16": "iPad Air (5th generation) (2022) (Wi-Fi)",
"iPad13,17": "iPad Air (5th generation) (2022) (Cellular)",
// iPad Pro
"iPad6,3": "iPad Pro 9.7\" (Wi-Fi)",
"iPad6,4": "iPad Pro 9.7\" (Cellular)",
"iPad6,7": "iPad Pro 12.9\" (Wi-Fi)",
"iPad6,8": "iPad Pro 12.9\" (Cellular)",
"iPad7,1": "iPad Pro 12.9\" (2nd generation) (Wi-Fi)",
"iPad7,2": "iPad Pro 12.9\" (2nd generation) (Cellular)",
"iPad7,3": "iPad Pro 10.5\" (Wi-Fi)",
"iPad7,4": "iPad Pro 10.5\" (Cellular)",
"iPad8,1": "iPad Pro 11\" (2018) (Wi-Fi)",
"iPad8,2": "iPad Pro 11\" (2018) (Wi-Fi, 1TB)",
"iPad8,3": "iPad Pro 11\" (2018) (Cellular)",
"iPad8,4": "iPad Pro 11\" (2018) (Cellular 1TB)",
"iPad8,5": "iPad Pro 12.9\" (3rd generation) (2018) (Wi-Fi)",
"iPad8,6": "iPad Pro 12.9\" (3rd generation) (2018) (Wi-Fi, 1TB)",
"iPad8,7": "iPad Pro 12.9\" (3rd generation) (2018) (Cellular)",
"iPad8,8": "iPad Pro 12.9\" (3rd generation) (2018) (Cellular, 1TB)",
"iPad8,9": "iPad Pro 11\" (2nd generation) (2020) (Wi-Fi)",
"iPad8,10": "iPad Pro 11\" (2nd generation) (2020) (Cellular)",
"iPad8,11": "iPad Pro 12.9\" (4th generation) (2020) (Wi-Fi)",
"iPad8,12": "iPad Pro 12.9\" (4th generation) (2020) (Cellular)",
"iPad13,4": "iPad Pro 11\" (3nd generation) (2021) (Wi-Fi)",
"iPad13,5": "iPad Pro 11\" (3nd generation) (2021) (Cellular US)",
"iPad13,6": "iPad Pro 11\" (3nd generation) (2021) (Cellular Global)",
"iPad13,7": "iPad Pro 11\" (3nd generation) (2021) (Cellular China)",
"iPad13,8": "iPad Pro 12.9\" (5th generation) (2021) (Wi-Fi)",
"iPad13,9": "iPad Pro 12.9\" (5th generation) (2021) (Cellular US)",
"iPad13,10": "iPad Pro 12.9\" (5th generation) (2021) (Cellular Global)",
"iPad13,11": "iPad Pro 12.9\" (5th generation) (2021) (Cellular China)",
"iPad14,3": "iPad Pro 11\" (4th generation) (2022) (Wi-Fi)",
"iPad14,4": "iPad Pro 11\" (4th generation) (2022) (Cellular)",
"iPad14,5": "iPad Pro 12.9\" (6th generation) (2022) (Wi-Fi)",
"iPad14,6": "iPad Pro 12.9\" (6th generation) (2022) (Cellular)",
// iPad mini
"iPad4,4": "iPad mini 2 (Wi-Fi)",
"iPad4,5": "iPad mini 2 (Cellular)",
"iPad4,6": "iPad mini 2 (China)",
"iPad4,7": "iPad mini 3 (Wi-Fi)",
"iPad4,8": "iPad mini 3 (Cellular)",
"iPad4,9": "iPad mini 3 (China)",
"iPad5,1": "iPad mini 4 (Wi-Fi)",
"iPad5,2": "iPad mini 4 (Cellular)",
"iPad11,1": "iPad mini (5th generation) (2019) (Wi-Fi)",
"iPad11,2": "iPad mini (5th generation) (2019) (Cellular)",
"iPad14,1": "iPad mini (6th generation) (2021) (Wi-Fi)",
"iPad14,2": "iPad mini (6th generation) (2021) (Cellular)",
// Apple TV
"AppleTV2,1": "Apple TV 2G",
"AppleTV3,1": "Apple TV 3",
"AppleTV3,2": "Apple TV 3 (2013)",
"AppleTV5,3": "Apple TV 4",
"AppleTV6,2": "Apple TV 4K",
"AppleTV11,1": "Apple TV 4K (2nd generation)",
// Apple Watch
"Watch1,1": "Apple Watch (1st generation) (38mm)",
"Watch1,2": "Apple Watch (1st generation) (42mm)",
"Watch2,6": "Apple Watch Series 1 (38mm)",
"Watch2,7": "Apple Watch Series 1 (42mm)",
"Watch2,3": "Apple Watch Series 2 (38mm)",
"Watch2,4": "Apple Watch Series 2 (42mm)",
"Watch3,1": "Apple Watch Series 3 (38mm Cellular)",
"Watch3,2": "Apple Watch Series 3 (42mm Cellular)",
"Watch3,3": "Apple Watch Series 3 (38mm)",
"Watch3,4": "Apple Watch Series 3 (42mm)",
"Watch4,1": "Apple Watch Series 4 (40mm)",
"Watch4,2": "Apple Watch Series 4 (44mm)",
"Watch4,3": "Apple Watch Series 4 (40mm Cellular)",
"Watch4,4": "Apple Watch Series 4 (44mm Cellular)",
"Watch5,1": "Apple Watch Series 5 (40mm)",
"Watch5,2": "Apple Watch Series 5 (44mm)",
"Watch5,3": "Apple Watch Series 5 (40mm Cellular)",
"Watch5,4": "Apple Watch Series 5 (44mm Cellular)",
"Watch6,1": "Apple Watch Series 6 (40mm)",
"Watch6,2": "Apple Watch Series 6 (44mm)",
"Watch6,3": "Apple Watch Series 6 (40mm Cellular)",
"Watch6,4": "Apple Watch Series 6 (44mm Cellular)",
"Watch5,9": "Apple Watch SE (40mm)",
"Watch5,10": "Apple Watch SE (44mm)",
"Watch5,11": "Apple Watch SE (40mm Cellular)",
"Watch5,12": "Apple Watch SE (44mm Cellular)",
"Watch6,6": "Apple Watch Series 7 (41mm)",
"Watch6,7": "Apple Watch Series 7 (45mm)",
"Watch6,8": "Apple Watch Series 7 (41mm Cellular)",
"Watch6,9": "Apple Watch Series 7 (45mm Cellular)",
"Watch6,10": "Apple Watch SE (2nd gen) (40mm)",
"Watch6,11": "Apple Watch SE (2nd gen) (44mm)",
"Watch6,12": "Apple Watch SE (2nd gen) (40mm Cellular)",
"Watch6,13": "Apple Watch SE (2nd gen) (44mm Cellular)",
"Watch6,14": "Apple Watch Series 8 (41mm)",
"Watch6,15": "Apple Watch Series 8 (45mm)",
"Watch6,16": "Apple Watch Series 8 (41mm Cellular)",
"Watch6,17": "Apple Watch Series 8 (45mm Cellular)",
"Watch6,18": "Apple Watch Ultra",
// iMac
"iMac21,1": "iMac 24\" (M1, 2021)",
"iMac21,2": "iMac 24\" (M1, 2021)",
// Mac mini
"Macmini9,1": "Mac mini (M1, 2020)",
// MacBook Air
"MacBookAir10,1": "MacBook Air (M1, Late 2020)",
// MacBook Pro
"MacBookPro17,1": "MacBook Pro 13\" (M1, 2020)",
"MacBookPro18,3": "MacBook Pro 14\" (M1 Pro, 2021)",
"MacBookPro18,4": "MacBook Pro 14\" (M1 Max, 2021)",
"MacBookPro18,1": "MacBook Pro 16\" (M1 Pro, 2021)",
"MacBookPro18,2": "MacBook Pro 16\" (M1 Max, 2021)",
// Simulator
"i386": "Simulator",
"x86_64": "Simulator",
]
return deviceMap[platform] ?? platform
}
You can test it using following code:
print("Current device is: ", self.userDeviceName())
Objective-C
I also added new devices to the Objective-C code
Don't forget to import sys/sysctl.h
#import <sys/sysctl.h>
- (NSString *) userDeviceName {
size_t size;
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
char *machine = malloc(size);
sysctlbyname("hw.machine", machine, &size, NULL, 0);
NSString *platform = [NSString stringWithCString:machine encoding:NSUTF8StringEncoding];
free(machine);
NSDictionary *deviceMap = #{
// iPhone
#"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,2": #"iPhone XS",
#"iPhone11,6": #"iPhone XS Max",
#"iPhone11,8": #"iPhone XR",
#"iPhone12,1": #"iPhone 11",
#"iPhone12,3": #"iPhone 11 Pro",
#"iPhone12,5": #"iPhone 11 Pro Max",
#"iPhone12,8": #"iPhone SE (2nd generation) (2020)",
#"iPhone13,1": #"iPhone 12 mini",
#"iPhone13,2": #"iPhone 12",
#"iPhone13,3": #"iPhone 12 Pro",
#"iPhone13,4": #"iPhone 12 Pro Max",
#"iPhone14,4": #"iPhone 13 mini",
#"iPhone14,5": #"iPhone 13",
#"iPhone14,2": #"iPhone 13 Pro",
#"iPhone14,3": #"iPhone 13 Pro Max",
#"iPhone14,6": #"iPhone SE (3rd generation) (2022)",
#"iPhone14,7": #"iPhone 14",
#"iPhone14,8": #"iPhone 14 Plus",
#"iPhone15,2": #"iPhone 14 Pro",
#"iPhone15,3": #"iPhone 14 Pro Max",
// iPod touch
#"iPod7,1": #"iPod Touch (6th generation)",
#"iPod9,1": #"iPod Touch (7th generation) (2019)",
// iPad
#"iPad3,4": #"iPad (4th generation) (Wi-Fi)",
#"iPad3,5": #"iPad (4th generation) (GSM)",
#"iPad3,6": #"iPad (4th generation) (GSM+CDMA)",
#"iPad6,11": #"iPad (5th generation) 9.7\" (2017) (Wi-Fi)",
#"iPad6,12": #"iPad (5th generation) 9.7\" (2017) (Cellular)",
#"iPad7,5": #"iPad (6th generation) 9.7\" (2018) (Wi-Fi)",
#"iPad7,6": #"iPad (6th generation) 9.7\" (2018) (Cellular)",
#"iPad7,11": #"iPad (7th generation) 10.2\" (2019) (Wi-Fi)",
#"iPad7,12": #"iPad (7th generation) 10.2\" (2019) (Cellular)",
#"iPad11,6": #"iPad (8th generation) 10.2\" (2020) (Wi-Fi)",
#"iPad11,7": #"iPad (8th generation) 10.2\" (2020) (Cellular)",
#"iPad12,1": #"iPad (9th generation) 10.2\" (2021) (Wi-Fi)",
#"iPad12,2": #"iPad (9th generation) 10.2\" (2021) (Cellular)",
#"iPad13,18": #"iPad (10th generation) 10.9\" (2022) (Wi-Fi)",
#"iPad13,19": #"iPad (10th generation) 10.9\" (2022) (Cellular)",
// iPad Air
#"iPad4,1": #"iPad Air (Wi-Fi)",
#"iPad4,2": #"iPad Air (Cellular)",
#"iPad4,3": #"iPad Air (China)",
#"iPad5,3": #"iPad Air 2 (Wi-Fi)",
#"iPad5,4": #"iPad Air 2 (Cellular)",
#"iPad11,3": #"iPad Air (3rd generation) (2019) (Wi-Fi)",
#"iPad11,4": #"iPad Air (3rd generation) (2019) (Cellular)",
#"iPad13,1": #"iPad Air (4th generation) (2020) (Wi-Fi)",
#"iPad13,2": #"iPad Air (4th generation) (2020) (Cellular)",
#"iPad13,16": #"iPad Air (5th generation) (2022) (Wi-Fi)",
#"iPad13,17": #"iPad Air (5th generation) (2022) (Cellular)",
// iPad Pro
#"iPad6,3": #"iPad Pro 9.7\" (Wi-Fi)",
#"iPad6,4": #"iPad Pro 9.7\" (Cellular)",
#"iPad6,7": #"iPad Pro 12.9\" (Wi-Fi)",
#"iPad6,8": #"iPad Pro 12.9\" (Cellular)",
#"iPad7,1": #"iPad Pro 12.9\" (2nd generation) (Wi-Fi)",
#"iPad7,2": #"iPad Pro 12.9\" (2nd generation) (Cellular)",
#"iPad7,3": #"iPad Pro 10.5\" (Wi-Fi)",
#"iPad7,4": #"iPad Pro 10.5\" (Cellular)",
#"iPad8,1": #"iPad Pro 11\" (2018) (Wi-Fi)",
#"iPad8,2": #"iPad Pro 11\" (2018) (Wi-Fi, 1TB)",
#"iPad8,3": #"iPad Pro 11\" (2018) (Cellular)",
#"iPad8,4": #"iPad Pro 11\" (2018) (Cellular 1TB)",
#"iPad8,5": #"iPad Pro 12.9\" (3rd generation) (2018) (Wi-Fi)",
#"iPad8,6": #"iPad Pro 12.9\" (3rd generation) (2018) (Wi-Fi, 1TB)",
#"iPad8,7": #"iPad Pro 12.9\" (3rd generation) (2018) (Cellular)",
#"iPad8,8": #"iPad Pro 12.9\" (3rd generation) (2018) (Cellular, 1TB)",
#"iPad8,9": #"iPad Pro 11\" (2nd generation) (2020) (Wi-Fi)",
#"iPad8,10": #"iPad Pro 11\" (2nd generation) (2020) (Cellular)",
#"iPad8,11": #"iPad Pro 12.9\" (4th generation) (2020) (Wi-Fi)",
#"iPad8,12": #"iPad Pro 12.9\" (4th generation) (2020) (Cellular)",
#"iPad13,4": #"iPad Pro 11\" (3nd generation) (2021) (Wi-Fi)",
#"iPad13,5": #"iPad Pro 11\" (3nd generation) (2021) (Cellular US)",
#"iPad13,6": #"iPad Pro 11\" (3nd generation) (2021) (Cellular Global)",
#"iPad13,7": #"iPad Pro 11\" (3nd generation) (2021) (Cellular China)",
#"iPad13,8": #"iPad Pro 12.9\" (5th generation) (2021) (Wi-Fi)",
#"iPad13,9": #"iPad Pro 12.9\" (5th generation) (2021) (Cellular US)",
#"iPad13,10": #"iPad Pro 12.9\" (5th generation) (2021) (Cellular Global)",
#"iPad13,11": #"iPad Pro 12.9\" (5th generation) (2021) (Cellular China)",
#"iPad14,3": #"iPad Pro 11\" (4th generation) (2022) (Wi-Fi)",
#"iPad14,4": #"iPad Pro 11\" (4th generation) (2022) (Cellular)",
#"iPad14,5": #"iPad Pro 12.9\" (6th generation) (2022) (Wi-Fi)",
#"iPad14,6": #"iPad Pro 12.9\" (6th generation) (2022) (Cellular)",
// iPad mini
#"iPad4,4": #"iPad mini 2 (Wi-Fi)",
#"iPad4,5": #"iPad mini 2 (Cellular)",
#"iPad4,6": #"iPad mini 2 (China)",
#"iPad4,7": #"iPad mini 3 (Wi-Fi)",
#"iPad4,8": #"iPad mini 3 (Cellular)",
#"iPad4,9": #"iPad mini 3 (China)",
#"iPad5,1": #"iPad mini 4 (Wi-Fi)",
#"iPad5,2": #"iPad mini 4 (Cellular)",
#"iPad11,1": #"iPad mini (5th generation) (2019) (Wi-Fi)",
#"iPad11,2": #"iPad mini (5th generation) (2019) (Cellular)",
#"iPad14,1": #"iPad mini (6th generation) (2021) (Wi-Fi)",
#"iPad14,2": #"iPad mini (6th generation) (2021) (Cellular)",
// Apple TV
#"AppleTV2,1": #"Apple TV 2G",
#"AppleTV3,1": #"Apple TV 3",
#"AppleTV3,2": #"Apple TV 3 (2013)",
#"AppleTV5,3": #"Apple TV 4",
#"AppleTV6,2": #"Apple TV 4K",
#"AppleTV11,1": #"Apple TV 4K (2nd generation)",
// Apple Watch
#"Watch1,1": #"Apple Watch (1st generation) (38mm)",
#"Watch1,2": #"Apple Watch (1st generation) (42mm)",
#"Watch2,6": #"Apple Watch Series 1 (38mm)",
#"Watch2,7": #"Apple Watch Series 1 (42mm)",
#"Watch2,3": #"Apple Watch Series 2 (38mm)",
#"Watch2,4": #"Apple Watch Series 2 (42mm)",
#"Watch3,1": #"Apple Watch Series 3 (38mm Cellular)",
#"Watch3,2": #"Apple Watch Series 3 (42mm Cellular)",
#"Watch3,3": #"Apple Watch Series 3 (38mm)",
#"Watch3,4": #"Apple Watch Series 3 (42mm)",
#"Watch4,1": #"Apple Watch Series 4 (40mm)",
#"Watch4,2": #"Apple Watch Series 4 (44mm)",
#"Watch4,3": #"Apple Watch Series 4 (40mm Cellular)",
#"Watch4,4": #"Apple Watch Series 4 (44mm Cellular)",
#"Watch5,1": #"Apple Watch Series 5 (40mm)",
#"Watch5,2": #"Apple Watch Series 5 (44mm)",
#"Watch5,3": #"Apple Watch Series 5 (40mm Cellular)",
#"Watch5,4": #"Apple Watch Series 5 (44mm Cellular)",
#"Watch6,1": #"Apple Watch Series 6 (40mm)",
#"Watch6,2": #"Apple Watch Series 6 (44mm)",
#"Watch6,3": #"Apple Watch Series 6 (40mm Cellular)",
#"Watch6,4": #"Apple Watch Series 6 (44mm Cellular)",
#"Watch5,9": #"Apple Watch SE (40mm)",
#"Watch5,10": #"Apple Watch SE (44mm)",
#"Watch5,11": #"Apple Watch SE (40mm Cellular)",
#"Watch5,12": #"Apple Watch SE (44mm Cellular)",
#"Watch6,6": #"Apple Watch Series 7 (41mm)",
#"Watch6,7": #"Apple Watch Series 7 (45mm)",
#"Watch6,8": #"Apple Watch Series 7 (41mm Cellular)",
#"Watch6,9": #"Apple Watch Series 7 (45mm Cellular)",
#"Watch6,10": #"Apple Watch SE (2nd gen) (40mm)",
#"Watch6,11": #"Apple Watch SE (2nd gen) (44mm)",
#"Watch6,12": #"Apple Watch SE (2nd gen) (40mm Cellular)",
#"Watch6,13": #"Apple Watch SE (2nd gen) (44mm Cellular)",
#"Watch6,14": #"Apple Watch Series 8 (41mm)",
#"Watch6,15": #"Apple Watch Series 8 (45mm)",
#"Watch6,16": #"Apple Watch Series 8 (41mm Cellular)",
#"Watch6,17": #"Apple Watch Series 8 (45mm Cellular)",
#"Watch6,18": #"Apple Watch Ultra",
// iMac
#"iMac21,1": #"iMac 24\" (M1, 2021)",
#"iMac21,2": #"iMac 24\" (M1, 2021)",
// Mac mini
#"Macmini9,1": #"Mac mini (M1, 2020)",
// MacBook Air
#"MacBookAir10,1": #"MacBook Air (M1, Late 2020)",
// MacBook Pro
#"MacBookPro17,1": #"MacBook Pro 13\" (M1, 2020)",
#"MacBookPro18,3": #"MacBook Pro 14\" (M1 Pro, 2021)",
#"MacBookPro18,4": #"MacBook Pro 14\" (M1 Max, 2021)",
#"MacBookPro18,1": #"MacBook Pro 16\" (M1 Pro, 2021)",
#"MacBookPro18,2": #"MacBook Pro 16\" (M1 Max, 2021)",
// Simulator
#"i386": #"Simulator",
#"x86_64": #"Simulator",
};
return deviceMap[platform] ? deviceMap[platform] : platform;
}
You can test it using following code:
NSLog(#"Current device is: %#", [self userDeviceName]);
if([UIDevice currentDevice].userInterfaceIdiom==UIUserInterfaceIdiomPad) {
//Device is ipad
}else{
//Device is iphone
}
Updated platform strings for iPad Air 2 and iPad mini 3:
- (NSString *)platformString
{
NSString *platform = [self platform];
if ([platform isEqualToString:#"iPhone1,1"]) return #"iPhone 1G";
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,3"]) return #"Verizon iPhone 4";
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,1"]) return #"iPhone 6 Plus";
if ([platform isEqualToString:#"iPhone7,2"]) return #"iPhone 6";
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";
if ([platform isEqualToString:#"iPad2,1"]) return #"iPad 2 (WiFi)";
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 (WiFi)";
if ([platform isEqualToString:#"iPad2,5"]) return #"iPad Mini (WiFi)";
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 3 (WiFi)";
if ([platform isEqualToString:#"iPad3,2"]) return #"iPad 3 (GSM+CDMA)";
if ([platform isEqualToString:#"iPad3,3"]) return #"iPad 3 (GSM)";
if ([platform isEqualToString:#"iPad3,4"]) return #"iPad 4 (WiFi)";
if ([platform isEqualToString:#"iPad3,5"]) return #"iPad 4 (GSM)";
if ([platform isEqualToString:#"iPad3,6"]) return #"iPad 4 (GSM+CDMA)";
if ([platform isEqualToString:#"iPad4,1"]) return #"iPad Air (WiFi)";
if ([platform isEqualToString:#"iPad4,2"]) return #"iPad Air (Cellular)";
if ([platform isEqualToString:#"iPad4,4"]) return #"iPad mini 2G (WiFi)";
if ([platform isEqualToString:#"iPad4,5"]) return #"iPad mini 2G (Cellular)";
if ([platform isEqualToString:#"iPad4,7"]) return #"iPad mini 3 (WiFi)";
if ([platform isEqualToString:#"iPad4,8"]) return #"iPad mini 3 (Cellular)";
if ([platform isEqualToString:#"iPad4,9"]) return #"iPad mini 3 (China Model)";
if ([platform isEqualToString:#"iPad5,3"]) return #"iPad Air 2 (WiFi)";
if ([platform isEqualToString:#"iPad5,4"]) return #"iPad Air 2 (Cellular)";
if ([platform isEqualToString:#"iPad6,8"]) return #"iPad Pro";
if ([platform isEqualToString:#"i386"]) return #"Simulator";
if ([platform isEqualToString:#"x86_64"]) return #"Simulator";
return platform;
}
More usable
#include <sys/types.h>
#include <sys/sysctl.h>
#interface UIDevice(Hardware)
- (NSString *) platform;
- (BOOL)hasRetinaDisplay;
- (BOOL)hasMultitasking;
- (BOOL)hasCamera;
#end
#implementation UIDevice(Hardware)
- (NSString *) platform{
int mib[2];
size_t len;
char *machine;
mib[0] = CTL_HW;
mib[1] = HW_MACHINE;
sysctl(mib, 2, NULL, &len, NULL, 0);
machine = malloc(len);
sysctl(mib, 2, machine, &len, NULL, 0);
NSString *platform = [NSString stringWithCString:machine encoding:NSASCIIStringEncoding];
free(machine);
return platform;
}
- (BOOL)hasRetinaDisplay {
NSString *platform = [self platform];
BOOL ret = YES;
if ([platform isEqualToString:#"iPhone1,1"]) {
ret = NO;
}
else
if ([platform isEqualToString:#"iPhone1,2"]) ret = NO;
else
if ([platform isEqualToString:#"iPhone2,1"]) ret = NO;
else
if ([platform isEqualToString:#"iPod1,1"]) ret = NO;
else
if ([platform isEqualToString:#"iPod2,1"]) ret = NO;
else
if ([platform isEqualToString:#"iPod3,1"]) ret = NO;
return ret;
}
- (BOOL)hasMultitasking {
if ([self respondsToSelector:#selector(isMultitaskingSupported)]) {
return [self isMultitaskingSupported];
}
return NO;
}
- (BOOL)hasCamera {
BOOL ret = NO;
// check camera availability
return ret;
}
#end
you can reading properties with
NSLog(#"platform %#, retita %#, multitasking %#", [[UIDevice currentDevice] platform], [[UIDevice currentDevice] hasRetinaDisplay] ? #"YES" : #"NO" , [[UIDevice currentDevice] hasMultitasking] ? #"YES" : #"NO");
Here's a minor update with new models:
- (NSString *) platformString{
NSString *platform = [self platform];
if ([platform isEqualToString:#"iPhone1,1"]) return #"iPhone 1G";
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:#"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:#"i386"]) return #"iPhone Simulator";
return platform;
}
I know an answer has been ticked already, but for future reference, you could always use the device screen size to figure out which device it is like so:
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
CGSize result = [[UIScreen mainScreen] bounds].size;
if (result.height == 480) {
// 3.5 inch display - iPhone 4S and below
NSLog(#"Device is an iPhone 4S or below");
}
else if (result.height == 568) {
// 4 inch display - iPhone 5
NSLog(#"Device is an iPhone 5/S/C");
}
else if (result.height == 667) {
// 4.7 inch display - iPhone 6
NSLog(#"Device is an iPhone 6");
}
else if (result.height == 736) {
// 5.5 inch display - iPhone 6 Plus
NSLog(#"Device is an iPhone 6 Plus");
}
}
else if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
// iPad 9.7 or 7.9 inch display.
NSLog(#"Device is an iPad.");
}
Just adding the iPhone 4S device code to this thread...
The iPhone 4S will return the string #"iPhone4,1".
How about this code, if new version was released, you will identifier with the last know device
- (NSString *)getModel {
size_t size;
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
char *model = malloc(size);
sysctlbyname("hw.machine", model, &size, NULL, 0);
NSString *sDeviceModel = [NSString stringWithCString:model encoding:NSUTF8StringEncoding];
free(model);
if ([sDeviceModel isEqual:#"i386"]) return #"Simulator"; //iPhone Simulator
if ([sDeviceModel isEqual:#"iPhone1,1"]) return #"iPhone1G"; //iPhone 1G
if ([sDeviceModel isEqual:#"iPhone1,2"]) return #"iPhone3G"; //iPhone 3G
if ([sDeviceModel isEqual:#"iPhone2,1"]) return #"iPhone3GS"; //iPhone 3GS
if ([sDeviceModel isEqual:#"iPhone3,1"]) return #"iPhone3GS"; //iPhone 4 - AT&T
if ([sDeviceModel isEqual:#"iPhone3,2"]) return #"iPhone3GS"; //iPhone 4 - Other carrier
if ([sDeviceModel isEqual:#"iPhone3,3"]) return #"iPhone4"; //iPhone 4 - Other carrier
if ([sDeviceModel isEqual:#"iPhone4,1"]) return #"iPhone4S"; //iPhone 4S
if ([sDeviceModel isEqual:#"iPod1,1"]) return #"iPod1stGen"; //iPod Touch 1G
if ([sDeviceModel isEqual:#"iPod2,1"]) return #"iPod2ndGen"; //iPod Touch 2G
if ([sDeviceModel isEqual:#"iPod3,1"]) return #"iPod3rdGen"; //iPod Touch 3G
if ([sDeviceModel isEqual:#"iPod4,1"]) return #"iPod4thGen"; //iPod Touch 4G
if ([sDeviceModel isEqual:#"iPad1,1"]) return #"iPadWiFi"; //iPad Wifi
if ([sDeviceModel isEqual:#"iPad1,2"]) return #"iPad3G"; //iPad 3G
if ([sDeviceModel isEqual:#"iPad2,1"]) return #"iPad2"; //iPad 2 (WiFi)
if ([sDeviceModel isEqual:#"iPad2,2"]) return #"iPad2"; //iPad 2 (GSM)
if ([sDeviceModel isEqual:#"iPad2,3"]) return #"iPad2"; //iPad 2 (CDMA)
NSString *aux = [[sDeviceModel componentsSeparatedByString:#","] objectAtIndex:0];
//If a newer version exist
if ([aux rangeOfString:#"iPhone"].location!=NSNotFound) {
int version = [[aux stringByReplacingOccurrencesOfString:#"iPhone" withString:#""] intValue];
if (version == 3) return #"iPhone4"
if (version >= 4) return #"iPhone4s";
}
if ([aux rangeOfString:#"iPod"].location!=NSNotFound) {
int version = [[aux stringByReplacingOccurrencesOfString:#"iPod" withString:#""] intValue];
if (version >=4) return #"iPod4thGen";
}
if ([aux rangeOfString:#"iPad"].location!=NSNotFound) {
int version = [[aux stringByReplacingOccurrencesOfString:#"iPad" withString:#""] intValue];
if (version ==1) return #"iPad3G";
if (version >=2) return #"iPad2";
}
//If none was found, send the original string
return sDeviceModel;
}
Adding to Arash's code, I don't care for my app what model I'm using, I just want to know what kind of device, so, I can test as follows:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
NSLog(#"I'm definitely an iPad");
} else {
NSString *deviceType = [UIDevice currentDevice].model;
if([deviceType rangeOfString:#"iPhone"].location!=NSNotFound)
{
NSLog(#"I must be an iPhone");
} else {
NSLog(#"I think I'm an iPod");
}
}
Based on the very good answers above, here is what I came up with. This is very similar to #Rodrigo's answer, but addresses #Oliver's concern from the comment on that answer. This also provides the option of including the model string in the output string.
+ (NSString *) deviceModel {
size_t size;
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
char *model = malloc(size);
sysctlbyname("hw.machine", model, &size, NULL, 0);
NSString *deviceModel = [NSString stringWithCString:model encoding:NSUTF8StringEncoding];
free(model);
return deviceModel;
}
+ (NSString *) deviceName {
NSString *deviceModel = [DeviceGateway deviceModel];
if ([deviceModel isEqual:#"i386"]) return #"Simulator"; //iPhone Simulator
if ([deviceModel isEqual:#"iPhone1,1"]) return #"iPhone1G"; //iPhone 1G
if ([deviceModel isEqual:#"iPhone1,2"]) return #"iPhone3G"; //iPhone 3G
if ([deviceModel isEqual:#"iPhone2,1"]) return #"iPhone3GS"; //iPhone 3GS
if ([deviceModel isEqual:#"iPhone3,1"]) return #"iPhone4"; //iPhone 4 - AT&T
if ([deviceModel isEqual:#"iPhone3,2"]) return #"iPhone4"; //iPhone 4 - Other carrier
if ([deviceModel isEqual:#"iPhone3,3"]) return #"iPhone4"; //iPhone 4 - Other carrier
if ([deviceModel isEqual:#"iPhone4,1"]) return #"iPhone4S"; //iPhone 4S
if ([deviceModel isEqual:#"iPod1,1"]) return #"iPod1stGen"; //iPod Touch 1G
if ([deviceModel isEqual:#"iPod2,1"]) return #"iPod2ndGen"; //iPod Touch 2G
if ([deviceModel isEqual:#"iPod3,1"]) return #"iPod3rdGen"; //iPod Touch 3G
if ([deviceModel isEqual:#"iPod4,1"]) return #"iPod4thGen"; //iPod Touch 4G
if ([deviceModel isEqual:#"iPad1,1"]) return #"iPadWiFi"; //iPad Wifi
if ([deviceModel isEqual:#"iPad1,2"]) return #"iPad3G"; //iPad 3G
if ([deviceModel isEqual:#"iPad2,1"]) return #"iPad2"; //iPad 2 (WiFi)
if ([deviceModel isEqual:#"iPad2,2"]) return #"iPad2"; //iPad 2 (GSM)
if ([deviceModel isEqual:#"iPad2,3"]) return #"iPad2"; //iPad 2 (CDMA)
NSString *aux = [[deviceModel componentsSeparatedByString:#","] objectAtIndex:0];
//If a newer version exists
if ([aux rangeOfString:#"iPhone"].location != NSNotFound) {
int version = [[aux stringByReplacingOccurrencesOfString:#"iPhone" withString:#""] intValue];
if (version == 3) return #"iPhone4";
if (version == 4) return #"iPhone4s";
return #"Newer iPhone";
}
if ([aux rangeOfString:#"iPod"].location != NSNotFound) {
int version = [[aux stringByReplacingOccurrencesOfString:#"iPod" withString:#""] intValue];
if (version == 4) return #"iPod4thGen";
return #"Newer iPod";
}
if ([aux rangeOfString:#"iPad"].location != NSNotFound) {
int version = [[aux stringByReplacingOccurrencesOfString:#"iPad" withString:#""] intValue];
if (version == 1) return #"iPad3G";
if (version == 2) return #"iPad2";
return #"Newer iPad";
}
//If none was found, send the original string
return deviceModel;
}
+ (NSString *) deviceNameWithDeviceModel:(BOOL)shouldIncludeDeviceModel {
if (shouldIncludeDeviceModel) {
return [NSString stringWithFormat:#"%# (%#)", [DeviceGateway deviceName], [DeviceGateway deviceModel]];
}
return [DeviceGateway deviceName];
}
There's a pretty mature library (by me) for that called SDVersion.
You can check for running device's model, screen size and many other parameters. It also supports OSX.
Example:
// Check for device model
if ([SDVersion deviceVersion] == iPhone6)
NSLog(#"You got the iPhone 6. Sweet 🍭!");
else if ([SDVersion deviceVersion] == iPhone6Plus)
NSLog(#"iPhone 6 Plus? Bigger is better!");
else if ([SDVersion deviceVersion] == iPadAir2)
NSLog(#"You own an iPad Air 2 🌀!");
// Check for device screen size
if ([SDVersion deviceSize] == Screen4inch)
NSLog(#"Your screen is 4 inches");
NSString *deviceType = [UIDevice currentDevice].model;
#import <sys/utsname.h>
NSString *iPhone = [self iPhoneVersion];
-(NSString*)iPhoneVersion
{
NSString *platform;
struct utsname systemInfo;
uname(&systemInfo);
platform = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
if ([platform isEqualToString:#"iPhone1,1"]) return #"iPhone 1G";
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,3"]) return #"VerizoniPhone 4";
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:#"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";
if ([platform isEqualToString:#"iPad2,1"]) return #"iPad 2 (WiFi)";
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 (WiFi)";
if ([platform isEqualToString:#"iPad2,5"]) return #"iPad Mini (WiFi)";
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 3 (WiFi)";
if ([platform isEqualToString:#"iPad3,2"]) return #"iPad 3 (GSM+CDMA)";
if ([platform isEqualToString:#"iPad3,3"]) return #"iPad 3 (GSM)";
if ([platform isEqualToString:#"iPad3,4"]) return #"iPad 4 (WiFi)";
if ([platform isEqualToString:#"iPad3,5"]) return #"iPad 4 (GSM)";
if ([platform isEqualToString:#"iPad3,6"]) return #"iPad 4 (GSM+CDMA)";
if ([platform isEqualToString:#"iPad4,1"]) return #"iPad Air (WiFi)";
if ([platform isEqualToString:#"iPad4,2"]) return #"iPad Air (Cellular)";
if ([platform isEqualToString:#"iPad4,3"]) return #"iPad Air";
if ([platform isEqualToString:#"iPad4,4"]) return #"iPad Mini 2G (WiFi)";
if ([platform isEqualToString:#"iPad4,5"]) return #"iPad Mini 2G (Cellular)";
if ([platform isEqualToString:#"iPad4,6"]) return #"iPad Mini 2G";
if ([platform isEqualToString:#"iPad4,7"]) return #"iPad Mini 3 (WiFi)";
if ([platform isEqualToString:#"iPad4,8"]) return #"iPad Mini 3 (Cellular)";
if ([platform isEqualToString:#"iPad4,9"]) return #"iPad Mini 3 (China)";
if ([platform isEqualToString:#"iPad5,3"]) return #"iPad Air 2 (WiFi)";
if ([platform isEqualToString:#"iPad5,4"]) return #"iPad Air 2 (Cellular)";
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:#"i386"]) return #"Simulator";
if ([platform isEqualToString:#"x86_64"]) return #"Simulator";
return platform;
}
I took it a bit further and converted the big "isEqualToString" block into a classification of bit masks for the device type, the generation, and that other qualifier after the comma (I'm calling it the sub generation). It is wrapped in a class with a singleton call SGPlatform which avoids a lot of repetitive string operations. Code is available https://github.com/danloughney/spookyGroup
The class lets you do things like this:
if ([SGPlatform iPad] && [SGPlatform generation] > 3) {
// set for high performance
}
and
switch ([SGPlatform deviceMask]) {
case DEVICE_IPHONE:
break;
case DEVICE_IPAD:
break;
case DEVICE_IPAD_MINI:
break;
}
The classification of the devices is in the platformBits method. That method should be very familiar to the readers of this thread. I have classified the devices by their type and generation because I'm mostly interested in the overall performance, but the source can be tweaked to provide any classification that you are interested in, retina screen, networking capabilities, etc..
Below mentioned code snippet should help :
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
// iPhone device
}
else if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
// iPad device
}
else {
// Other device i.e. iPod
}
- (BOOL)deviceiPhoneOriPod
{
NSString *deviceType = [UIDevice currentDevice].model;
if([deviceType rangeOfString:#"iPhone"].location!=NSNotFound)
return YES;
else
return NO;
}
Dutchie432 and Brian Robbins have provided great solutions. But there's still one model missing, the Verizon iPhone 4. Here's the missing line.
if ([platform isEqualToString:#"iPhone3,2"]) return #"iPhone 4"; //Verizon
I like Erica Sadun's stuff. She includes AppleTV devices and others you might not think of.
https://github.com/erica/uidevice-extension/blob/master/UIDevice-Hardware.h
The possible vales of
[[UIDevice currentDevice] model];
are iPod touch, iPhone, iPhone Simulator, iPad, iPad Simulator
If you want to know which hardware iOS is ruining on like iPhone3, iPhone4, iPhone5 etc below is the code for that
NOTE: The below code may not contain all device's string, I'm with other guys are maintaining the same code on GitHub so please take the latest code from there
Objective-C : GitHub/DeviceUtil
Swift : GitHub/DeviceGuru
#include <sys/types.h>
#include <sys/sysctl.h>
- (NSString*)hardwareDescription {
NSString *hardware = [self hardwareString];
if ([hardware isEqualToString:#"iPhone1,1"]) return #"iPhone 2G";
if ([hardware isEqualToString:#"iPhone1,2"]) return #"iPhone 3G";
if ([hardware isEqualToString:#"iPhone3,1"]) return #"iPhone 4";
if ([hardware isEqualToString:#"iPhone4,1"]) return #"iPhone 4S";
if ([hardware isEqualToString:#"iPhone5,1"]) return #"iPhone 5";
if ([hardware isEqualToString:#"iPod1,1"]) return #"iPodTouch 1G";
if ([hardware isEqualToString:#"iPod2,1"]) return #"iPodTouch 2G";
if ([hardware isEqualToString:#"iPad1,1"]) return #"iPad";
if ([hardware isEqualToString:#"iPad2,6"]) return #"iPad Mini";
if ([hardware isEqualToString:#"iPad4,1"]) return #"iPad Air WIFI";
//there are lots of other strings too, checkout the github repo
//link is given at the top of this answer
if ([hardware isEqualToString:#"i386"]) return #"Simulator";
if ([hardware isEqualToString:#"x86_64"]) return #"Simulator";
return nil;
}
- (NSString*)hardwareString {
size_t size = 100;
char *hw_machine = malloc(size);
int name[] = {CTL_HW,HW_MACHINE};
sysctl(name, 2, hw_machine, &size, NULL, 0);
NSString *hardware = [NSString stringWithUTF8String:hw_machine];
free(hw_machine);
return hardware;
}
Answer in Swift 3,
struct DeviceInformation {
// UIDevice.current.model's value is "iPhone" or "iPad",which does not include details; the following "model" is detailed, such as, iPhone7,1 is actually iPhone 6 plus
static let model: String = {
var size = 0
sysctlbyname("hw.machine", nil, &size, nil, 0)
var machine = [CChar](repeating: 0, count: Int(size))
sysctlbyname("hw.machine", &machine, &size, nil, 0)
return String(cString: machine)
}()
static let uuid = UIDevice.current.identifierForVendor?.uuidString ?? ""
static let idForAdService = ASIdentifierManager.shared().advertisingIdentifier.uuidString
static func diviceTypeReadableName() -> String {
switch model {
case "iPhone1,1": return "iPhone 1G"
case "iPhone1,2": return "iPhone 3G"
case "iPhone2,1": return "iPhone 3GS"
case "iPhone3,1": return "iPhone 4"
case "iPhone3,3": return "iPhone 4 (Verizon)"
case "iPhone4,1": return "iPhone 4S"
case "iPhone5,1": return "iPhone 5 (GSM)"
case "iPhone5,2": return "iPhone 5 (GSM+CDMA)"
case "iPhone5,3": return "iPhone 5c (GSM)"
case "iPhone5,4": return "iPhone 5c (GSM+CDMA)"
case "iPhone6,1": return "iPhone 5s (GSM)"
case "iPhone6,2": return "iPhone 5s (GSM+CDMA)"
case "iPhone7,2": return "iPhone 6"
case "iPhone7,1": return "iPhone 6 Plus"
case "iPhone8,1": return "iPhone 6s"
case "iPhone8,2": return "iPhone 6s Plus"
case "iPhone8,4": return "iPhone SE"
case "iPhone9,1": return "iPhone 7"
case "iPhone9,3": return "iPhone 7"
case "iPhone9,2": return "iPhone 7 Plus"
case "iPhone9,4": return "iPhone 7 Plus"
case "iPod1,1": return "iPod Touch 1G"
case "iPod2,1": return "iPod Touch 2G"
case "iPod3,1": return "iPod Touch 3G"
case "iPod4,1": return "iPod Touch 4G"
case "iPod5,1": return "iPod Touch 5G"
case "iPod7,1": return "iPod Touch 6G"
case "iPad1,1": return "iPad 1G"
case "iPad2,1": return "iPad 2 (Wi-Fi)"
case "iPad2,2": return "iPad 2 (GSM)"
case "iPad2,3": return "iPad 2 (CDMA)"
case "iPad2,4": return "iPad 2 (Wi-Fi)"
case "iPad2,5": return "iPad Mini (Wi-Fi)"
case "iPad2,6": return "iPad Mini (GSM)"
case "iPad2,7": return "iPad Mini (GSM+CDMA)"
case "iPad3,1": return "iPad 3 (Wi-Fi)"
case "iPad3,2": return "iPad 3 (GSM+CDMA)"
case "iPad3,3": return "iPad 3 (GSM)"
case "iPad3,4": return "iPad 4 (Wi-Fi)"
case "iPad3,5": return "iPad 4 (GSM)"
case "iPad3,6": return "iPad 4 (GSM+CDMA)"
case "iPad4,1": return "iPad Air (Wi-Fi)"
case "iPad4,2": return "iPad Air (Cellular)"
case "iPad4,3": return "iPad Air (China)"
case "iPad4,4": return "iPad Mini 2G (Wi-Fi)"
case "iPad4,5": return "iPad Mini 2G (Cellular)"
case "iPad4,6": return "iPad Mini 2G (China)"
case "iPad4,7": return "iPad Mini 3 (Wi-Fi)"
case "iPad4,8": return "iPad Mini 3 (Cellular)"
case "iPad4,9": return "iPad Mini 3 (China)"
case "iPad5,1": return "iPad Mini 4 (Wi-Fi)"
case "iPad5,2": return "iPad Mini 4 (Cellular)"
case "iPad5,3": return "iPad Air 2 (Wi-Fi)"
case "iPad5,4": return "iPad Air 2 (Cellular)"
case "iPad6,3": return "iPad Pro 9.7' (Wi-Fi)"
case "iPad6,4": return "iPad Pro 9.7' (Cellular)"
case "iPad6,7": return "iPad Pro 12.9' (Wi-Fi)"
case "iPad6,8": return "iPad Pro 12.9' (Cellular)"
case "AppleTV2,1": return "Apple TV 2G"
case "AppleTV3,1": return "Apple TV 3"
case "AppleTV3,2": return "Apple TV 3 (2013)"
case "AppleTV5,3": return "Apple TV 4"
case "Watch1,1": return "Apple Watch Series 1 (38mm, S1)"
case "Watch1,2": return "Apple Watch Series 1 (42mm, S1)"
case "Watch2,6": return "Apple Watch Series 1 (38mm, S1P)"
case "Watch2,7": return "Apple Watch Series 1 (42mm, S1P)"
case "Watch2,3": return "Apple Watch Series 2 (38mm, S2)"
case "Watch2,4": return "Apple Watch Series 2 (42mm, S2)"
case "i386": return "Simulator"
case "x86_64": return "Simulator"
default:
return ""
}
}
}
For simple comparison I always like macro:
#define IS_IPOD [[UIDevice currentDevice].model containsString:#"iPod"]
#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
It's simple and easy to use.
I'd like to add that to retrieve the front and enclosure color of the device there's a private API:
UIDevice *device = [UIDevice currentDevice];
SEL selector = NSSelectorFromString([device.systemVersion hasPrefix:#"7"] ? #"_deviceInfoForKey:" : #"deviceInfoForKey:");
if ([device respondsToSelector:selector]) {
NSLog(#"DeviceColor: %# DeviceEnclosureColor: %#", [device performSelector:selector withObject:#"DeviceColor"], [device performSelector:selector withObject:#"DeviceEnclosureColor"]);
}
I've blogged about this and provide a sample app:
http://www.futuretap.com/blog/device-colors/
NSString *deviceType = [[UIDevice currentDevice] systemName];
I can assure that the above suggested one will work in iOS 7 and above. I believe it will work in iOS 6 too. But am not sure about that.
You can check GBDeviceInfo on GitHub, also available via CocoaPods. It provides simple API for detecting various properties with support of all latest devices:
Device family
[GBDeviceInfo deviceDetails].family == GBDeviceFamilyiPhone;
Device model
[GBDeviceInfo deviceDetails].model == GBDeviceModeliPhone6.
For more see Readme.
To identifiy iPhone 4S, simply check the following:
var isIphone4S: Bool {
let width = UIScreen.main.bounds.size.width
let height = UIScreen.main.bounds.size.height
let proportions = width > height ? width / height : height / width
return proportions == 1.5 && UIDevice.current.model == "iPhone"
}
I've created an extension that lets you to have 3 levels of identification:
type of device
type of iPhone/iPad by inch
model of device
It updates with last iOS devices
UIDeviceDetector

iPod Touch with iOS8 is being detected as an iPhone

I have an app that in contact us section allows the user to call us depending on the device. If it is an iPhone it would show the number along with the Call button. If it is an iPod Touch it would just display the number. But since updating to iOS8 the iPod Touch is also being identified as an iPhone and is showing the Call button. Anybody know how to fix this? Any help is appreciated.
You can check to see if the iOS device can open a telephone link:
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:#"tel:+11111"]])
As mentioned in the following post:
How do I test if IOS device has telephone capabilities?
Do device type check as below :
- (NSString *) deviceType{
NSString *devicePlatform = [self deviceModel];
if ([devicePlatform isEqualToString:#"iPod1,1"]) return #"iPod Touch 1G";
if ([devicePlatform isEqualToString:#"iPod2,1"]) return #"iPod Touch 2G";
if ([devicePlatform isEqualToString:#"iPod3,1"]) return #"iPod Touch 3G";
if ([devicePlatform isEqualToString:#"iPod4,1"]) return #"iPod Touch 4G";
if ([devicePlatform isEqualToString:#"iPad1,1"]) return #"iPad";
if ([devicePlatform isEqualToString:#"iPod5,1"]) return #"iPod Touch 5G";
return devicePlatform;
}
- (NSString *) deviceModel{
size_t size;
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
char *machine = malloc(size);
sysctlbyname("hw.machine", machine, &size, NULL, 0);
NSString *platform = [NSString stringWithUTF8String:machine];
free(machine);
return platform;
}

Dropping iPhone 3GS Support for new app

Is it possible to drop the support of iPhone 3GS for new App?
Because I'm doing porting from iPad game to iPhone. The 480*320 resolution is too small. Its very hard to port my current game on it.. but iPhone4/4s with high resolution works fine!
Thanks
Take a look at UIRequiredDeviceCapabilities you can specify inside Info.plist.
There is no direct way to limit "device-support" to the iPhone 4(S) / iPad (2), but you can ask for front-facing-camerabecause that's only included in the iPhone-4-familiy :) On the other hand you'll also drop support for the original iPad if you use this way …
I'm not quite sure that you can do it from a build level. But you can do it from code level by detecting the device version like this (Not the best way of doing it),
- (NSString *) platformString{
    NSString *platform = [self platform];
    if ([platform isEqualToString:#"iPhone1,1"])    return #"iPhone 1G";
    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,3"])    return #"Verizon iPhone 4";
    if ([platform isEqualToString:#"iPhone4,1"])    return #"iPhone 4S";
    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:#"iPad1,1"])      return #"iPad";
    if ([platform isEqualToString:#"iPad2,1"])      return #"iPad 2 (WiFi)";
    if ([platform isEqualToString:#"iPad2,2"])      return #"iPad 2 (GSM)";
    if ([platform isEqualToString:#"iPad2,3"])      return #"iPad 2 (CDMA)";
    if ([platform isEqualToString:#"i386"])         return #"Simulator";
    if ([platform isEqualToString:#"x86_64"])       return #"Simulator";
    return platform;
}
Hope this will help you to a certain extent.
I don't think it's possible as I took a look in this great reference chart
http://blog.manbolo.com/2012/10/30/uirequireddevicecapabilities-and-device-compatibility-matrix
The best closest is to required front-camera or gyroscope but it will cut out iPad 1 from your support devices. I think I have to admit and do my best to support iPhone 3GS, I just don't want users to download and experience something bad even if it's small portion of users are still using it.
Add Required device capabilities to your info.plist and the value camera-flash. This will limit the app to only run on devices with camera flash (e.g. iPhone 4/4S) or use front-facing-camera to include iPad 2 and latest gen iPod Touch.

How to tell if Cocoa Touch device can make calls? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
iOS - Detecting whether or not device support phone calls?
I'm writing an iPhone application that provides a button to call a phone number. I'm using code like the following to dial the number using a tel: URL in the usual way:
NSURL* contactTelURL = [NSURL
URLWithString:[NSString
stringWithFormat:#"tel:%#",
contactTel]];
[[UIApplication sharedApplication] openURL:contactTelURL];
It works fine on a real iPhone, but I just get an 'Unsupported URL' alert in the simulator. Presumably that would also happen on an iPod Touch, though I haven't tested that. It would be nice to remove the button when running on a device that won't make calls.
Is there a way to detect programatically whether a Cocoa Touch device can make phone calls?
From Noah Witherspoon at Make a call from my iPhone application
the simulator doesn't support a lot of iOS's URL schemes, including those for the Phone, Maps, Youtube, and SMS apps. This is also the case for devices like the iPod touch and the iPad, which don't have phone capabilities; before using any URL scheme via -openURL:, you should check for support for that scheme using -canOpenURL:, which will return YES or NO depending on whether the current device supports the URL scheme you're using
So query [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:#"tel://"]]
to find out if the device can make calls.
From iphonedevelopment.blogspot.com
#import <sys/utsname.h>
enum {
MODEL_IPHONE_SIMULATOR,
MODEL_IPOD_TOUCH,
MODEL_IPHONE,
MODEL_IPHONE_3G
};
#interface DeviceDetection : NSObject
+ (uint) detectDevice;
+ (NSString *) returnDeviceName:(BOOL)ignoreSimulator;
#end
#implementation DeviceDetection
+ (uint) detectDevice {
NSString *model= [[UIDevice currentDevice] model];
// Some iPod Touch return "iPod Touch", others just "iPod"
NSString *iPodTouch = #"iPod Touch";
NSString *iPodTouchLowerCase = #"iPod touch";
NSString *iPodTouchShort = #"iPod";
NSString *iPhoneSimulator = #"iPhone Simulator";
uint detected;
if ([model compare:iPhoneSimulator] == NSOrderedSame) {
// iPhone simulator
detected = MODEL_IPHONE_SIMULATOR;
} else if ([model compare:iPodTouch] == NSOrderedSame) {
// iPod Touch
detected = MODEL_IPOD_TOUCH;
} else if ([model compare:iPodTouchLowerCase] == NSOrderedSame) {
// iPod Touch
detected = MODEL_IPOD_TOUCH;
} else if ([model compare:iPodTouchShort] == NSOrderedSame) {
// iPod Touch
detected = MODEL_IPOD_TOUCH;
} else {
// Could be an iPhone V1 or iPhone 3G (model should be "iPhone")
struct utsname u;
// u.machine could be "i386" for the simulator, "iPod1,1" on iPod Touch, "iPhone1,1" on iPhone V1 & "iPhone1,2" on iPhone3G
uname(&u);
if (!strcmp(u.machine, "iPhone1,1")) {
detected = MODEL_IPHONE;
} else {
detected = MODEL_IPHONE_3G;
}
}
return detected;
}
+ (NSString *) returnDeviceName:(BOOL)ignoreSimulator {
NSString *returnValue = #"Unknown";
switch ([DeviceDetection detectDevice]) {
case MODEL_IPHONE_SIMULATOR:
if (ignoreSimulator) {
returnValue = #"iPhone 3G";
} else {
returnValue = #"iPhone Simulator";
}
break;
case MODEL_IPOD_TOUCH:
returnValue = #"iPod Touch";
break;
case MODEL_IPHONE:
returnValue = #"iPhone";
break;
case MODEL_IPHONE_3G:
returnValue = #"iPhone 3G";
break;
default:
break;
}
return returnValue;
}
#end
Here is a simple code snippet I use to check the device model is a phone and not a simulator to make sure it can make calls.
if ([[[UIDevice currentDevice] model] rangeOfString:#"Phone"].location != NSNotFound &&
[[[UIDevice currentDevice] model] rangeOfString:#"Simulator"].location == NSNotFound ) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:#"tel:%#", number] ] ];
}
You could query [[UIDevice currentDevice] model], and check if it is an iPhone.

Resources