I'm writing an app that has different functionality depending on the model of iPhone. Is there a way to distinguish between iPhone 5, and 5c 5s? I can not do a check on the display because it is identical. Thanks in advance.
-
1http://stackoverflow.com/questions/448162/determine-device-iphone-ipod-touch-with-iphone-sdk – B.S. Oct 25 '13 at 08:01
-
If you want to identify a device on Xcode, plug it in and the Organizer will tell you. If you want to identify a device within your application code... – BoltClock Sep 18 '14 at 13:31
6 Answers
Objective-C & SWIFT
This is working on all version like iOS 6, iOS 7 and iOS 8 etc...
And updated for iPhone 6 & iPhone 6 Plus
-(void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
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];
NSLog(@"iPhone Device%@",[self platformType:platform]);
free(machine);
}
- (NSString *) platformType:(NSString *)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,2"]) return @"iPhone 6";
if ([platform isEqualToString:@"iPhone7,1"]) return @"iPhone 6 Plus";
if ([platform isEqualToString:@"iPhone8,1"]) return @"iPhone 6s";
if ([platform isEqualToString:@"iPhone8,2"]) return @"iPhone 6s Plus";
if ([platform isEqualToString:@"iPhone8,4"]) return @"iPhone SE";
if ([platform isEqualToString:@"iPhone9,1"]) return @"iPhone 7";
if ([platform isEqualToString:@"iPhone9,2"]) return @"iPhone 7 Plus";
if ([platform isEqualToString:@"iPhone9,3"]) return @"iPhone 7";
if ([platform isEqualToString:@"iPhone9,4"]) return @"iPhone 7 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;
}
this code is also AppStore safe.
SWIFT 3.2
override func viewDidLoad() {
super.viewDidLoad()
var sysInfo = utsname()
uname(&sysInfo)
let machine = Mirror(reflecting: sysInfo.machine)
let identifier = machine.children.reduce("") { identifier, element in
guard let value = element.value as? Int8, value != 0 else { return identifier }
return identifier + String(UnicodeScalar(UInt8(value)))
}
NSLog("Device Type ----> %@", self.platformType(platform: identifier as NSString));
print(self.platformType(platform: identifier as NSString))
}
func platformType(platform : NSString) -> NSString{
if platform.isEqual(to: "iPhone1,1") {
return "iPhone 1G"
}
else if platform.isEqual(to: "iPhone1,2"){
return "iPhone 3G"
}
else if platform.isEqual(to: "iPhone2,1"){
return "iPhone 3GS"
}
else if platform.isEqual(to: "iPhone3,1"){
return "iPhone 4"
}
else if platform.isEqual(to: "iPhone3,3"){
return "Verizon iPhone 4"
}
else if platform.isEqual(to: "iPhone4,1"){
return "iPhone 4S"
}
else if platform.isEqual(to: "iPhone5,1"){
return "iPhone 5 (GSM)"
}
else if platform.isEqual(to: "iPhone5,2"){
return "iPhone 5 (GSM+CDMA)"
}
else if platform.isEqual(to: "iPhone5,3"){
return "iPhone 5c (GSM)"
}
else if platform.isEqual(to: "iPhone5,4"){
return "iPhone 5c (GSM+CDMA)"
}
else if platform.isEqual(to: "iPhone6,1"){
return "iPhone 5s (GSM)"
}
else if platform.isEqual(to: "iPhone6,2"){
return "iPhone 5s (GSM+CDMA)"
}
else if platform.isEqual(to: "iPhone7,2"){
return "iPhone 6"
}
else if platform.isEqual(to: "iPhone7,1"){
return "iPhone 6 Plus"
}
else if platform.isEqual(to: "iPhone8,1"){
return "iPhone 6s"
}
else if platform.isEqual(to: "iPhone8,2"){
return "iPhone 6s Plus"
}
else if platform.isEqual(to: "iPhone8,4"){
return "iPhone SE"
}
else if platform.isEqual(to: "iPhone9,1"){
return "iPhone 7"
}
else if platform.isEqual(to: "iPhone9,2"){
return "iPhone 7 Plus"
}
else if platform.isEqual(to: "iPhone9,3"){
return "iPhone 7"
}
else if platform.isEqual(to: "iPhone9,4"){
return "iPhone 7 Plus"
}
else if platform.isEqual(to: "iPod1,1"){
return "iPod Touch 1G"
}
else if platform.isEqual(to: "iPod2,1"){
return "iPod Touch 2G"
}
else if platform.isEqual(to: "iPod3,1"){
return "iPod Touch 3G"
}
else if platform.isEqual(to: "iPod4,1"){
return "iPod Touch 4G"
}
else if platform.isEqual(to: "iPod5,1"){
return "iPod Touch 5G"
}
else if platform.isEqual(to: "iPad1,1"){
return "iPad"
}
else if platform.isEqual(to: "iPad2,1"){
return "iPad 2 (WiFi)"
}
else if platform.isEqual(to: "iPad2,2"){
return "iPad 2 (GSM)"
}
else if platform.isEqual(to: "iPad2,3"){
return "iPad 2 (CDMA)"
}
else if platform.isEqual(to: "iPad2,4"){
return "iPad 2 (WiFi)"
}
else if platform.isEqual(to: "iPad2,5"){
return "iPad Mini (WiFi)"
}
else if platform.isEqual(to: "iPad2,6"){
return "iPad Mini (GSM)"
}
else if platform.isEqual(to: "iPad2,7"){
return "iPad Mini (GSM+CDMA)"
}
else if platform.isEqual(to: "iPad3,1"){
return "iPad 3 (WiFi)"
}
else if platform.isEqual(to: "iPad3,2"){
return "iPad 3 (GSM+CDMA)"
}
else if platform.isEqual(to: "iPad3,3"){
return "iPad 3 (GSM)"
}
else if platform.isEqual(to: "iPad3,4"){
return "iPad 4 (WiFi)"
}
else if platform.isEqual(to: "iPad3,5"){
return "iPad 4 (GSM)"
}
else if platform.isEqual(to: "iPad3,6"){
return "iPad 4 (GSM+CDMA)"
}
else if platform.isEqual(to: "iPad4,1"){
return "iPad Air (WiFi)"
}
else if platform.isEqual(to: "iPad4,2"){
return "iPad Air (Cellular)"
}
else if platform.isEqual(to: "iPad4,3"){
return "iPad Air"
}
else if platform.isEqual(to: "iPad4,4"){
return "iPad Mini 2G (WiFi)"
}
else if platform.isEqual(to: "iPad4,5"){
return "iPad Mini 2G (Cellular)"
}
else if platform.isEqual(to: "iPad4,6"){
return "iPad Mini 2G";
}
else if platform.isEqual(to: "iPad4,7"){
return "iPad Mini 3 (WiFi)"
}
else if platform.isEqual(to: "iPad4,8"){
return "iPad Mini 3 (Cellular)"
}
else if platform.isEqual(to: "iPad4,9"){
return "iPad Mini 3 (China)"
}
else if platform.isEqual(to: "iPad5,3"){
return "iPad Air 2 (WiFi)"
}
else if platform.isEqual(to: "iPad5,4"){
return "iPad Air 2 (Cellular)"
}
else if platform.isEqual(to: "AppleTV2,1"){
return "Apple TV 2G"
}
else if platform.isEqual(to: "AppleTV3,1"){
return "Apple TV 3"
}
else if platform.isEqual(to: "AppleTV3,2"){
return "Apple TV 3 (2013)"
}
else if platform.isEqual(to: "i386"){
return "Simulator"
}
else if platform.isEqual(to: "x86_64"){
return "Simulator"
}
return platform
}

- 1
- 1

- 17,485
- 5
- 50
- 66
-
1Did *you* figure out all these cases? Bravo if you did! (Otherwise a link to the source would be appropriate.) – Martin R Oct 25 '13 at 08:26
-
2
-
-
sysctlbyname is said to be inavlid in C99 according to Xcode, but the app still runs. – rolling_codes Jun 09 '14 at 19:07
-
9
-
2Please update iPhone 6 (7,2) and 6 plus (7,1) , so this helpful answer remains updated – Bhumit Mehta Sep 18 '14 at 13:13
-
@Bhumit still i didn't check it so if you have got solution then please suggest me to update? – Dharmbir Singh Sep 18 '14 at 13:31
-
@Bhumit: If you're looking for an answer specific to those models why would you come to this question? This question isn't about those new models. It's specifically about iPhone 5, iPhone 5c and iPhone 5s. – BoltClock Sep 18 '14 at 13:33
-
2@DharmbirChoudhary : `iPhone7,1` for 6 plus and `iPhone 7,2` for iPhone 6 source is http://theiphonewiki.com/wiki/Models . And i understand that question is old but there is no harm in updating this. – Bhumit Mehta Sep 18 '14 at 13:41
-
1Not that it didn't deserve it in the first place but +1 for the update. – Popeye Sep 18 '14 at 14:22
-
1Thanks ! but this requires real device !!! I don't have 6 or 6 Plus so I need to test it on simulator ! what now ?! – iOS.Lover Sep 27 '14 at 18:20
-
@Mc.Lover If you want then you can identify using screen resolution. – Dharmbir Singh Sep 29 '14 at 04:45
-
Yes how would you do this with the simulator. I agree with Mc.Lover – uplearned.com Dec 19 '14 at 03:57
-
someone from apple used ipad 5,4 in my app while reviewing it. what is that? – Esqarrouth Dec 30 '14 at 13:20
-
@Esq This is iPad Air 2 (Cellular). And i've modified my answer. Please see it. – Dharmbir Singh Dec 31 '14 at 04:47
-
Here is a source: https://www.theiphonewiki.com/wiki/Models. It also mentions "Watch1,1" and "Watch1,2". – ofavre Jun 24 '15 at 09:51
-
Whats gonna happen when iphone 7 will release? Will be needed to update to code? – Yucel Bayram Aug 18 '16 at 11:34
-
-
-
Use this to get the device-model-identifier, like iPhone6,2 or iPhone 3,1. Then you can do an if statement and check, if the identifier is equal to a prefix and then you can assign the right name to a NSString.
Here is the code:
#import <sys/utsname.h>
NSString *deviceType;
struct utsname systemInfo;
uname(&systemInfo);
deviceType = [NSString stringWithCString:systemInfo.machine
encoding:NSUTF8StringEncoding];

- 8,139
- 6
- 78
- 111

- 3,525
- 8
- 50
- 98
-
-
Best answer. Although -platformType: method can be helpful here as well. – user1244109 Apr 23 '14 at 14:42
Here is a solution..
1) Define a device list with update iPhone 6s (8,1) and 6s plus (8,2) ::
//DeviceList
#define HARDWARE @{
@"i386": @"Simulator",
@"x86_64": @"Simulator",
@"iPod1,1": @"iPod Touch",
@"iPod2,1": @"iPod Touch 2nd Generation",
@"iPod3,1": @"iPod Touch 3rd Generation",
@"iPod4,1": @"iPod Touch 4th Generation",
@"iPhone1,1": @"iPhone",
@"iPhone1,2": @"iPhone 3G",
@"iPhone2,1": @"iPhone 3GS",
@"iPhone3,1": @"iPhone 4",
@"iPhone4,1": @"iPhone 4S",
@"iPhone5,1": @"iPhone 5",
@"iPhone5,2": @"iPhone 5",
@"iPhone5,3": @"iPhone 5c",
@"iPhone5,4": @"iPhone 5c",
@"iPhone6,1": @"iPhone 5s",
@"iPhone6,2": @"iPhone 5s",
@"iPad1,1": @"iPad",
@"iPad2,1": @"iPad 2",
@"iPad3,1": @"iPad 3rd Generation ",
@"iPad3,4": @"iPad 4th Generation ",
@"iPad2,5": @"iPad Mini",
@"iPad4,4": @"iPad Mini 2nd Generation - Wifi",
@"iPad4,5": @"iPad Mini 2nd Generation - Cellular",
@"iPad4,1": @"iPad Air 5th Generation - Wifi",
@"iPad4,2": @"iPad Air 5th Generation - Cellular",
@"iPhone7,1": @"iPhone 6 Plus",
@"iPhone7,2": @"iPhone 6",
@"iPhone8,1": @"iPhone 6S (GSM+CDMA)",
@"iPhone8,2": @"iPhone 6S+ (GSM+CDMA)"
}
2)Add header file::
#import <sys/utsname.h>
3) To get a device name::
//To get the Device_name
struct utsname systemInfo;
uname(&systemInfo);
deviceName=[HARDWARE objectForKey:[NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding]];
NSLog(@"Device Name::%@",deviceName);

- 6,929
- 3
- 27
- 43

- 15,269
- 2
- 94
- 81
-
-
1Great answer. It only had a slight syntax error, which is removed. Works perfectly. Many thanks. – Septronic Jan 04 '16 at 16:30
Try this library:
https://github.com/erica/uidevice-extension/
You can get things like this:
[[UIDevice currentDevice] platformType]; // ex: UIDevice4GiPhone
[[UIDevice currentDevice] platformString]; // ex: @"iPhone 4G"

- 20,382
- 3
- 43
- 62
-
3Correct me if I'm wrong, but the library is not up to date and does not list devices >iPhone 5 – tilo Oct 25 '13 at 08:15
I know i'm a bit ahead of myself, but does anyone know the platform for iphone 6? So if added to the list above, would it be iPhone6,3
and iPhone6,4
(just a wild guest...)
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)";

- 619
- 1
- 6
- 18
check out the model property in "UIDevice" class . Or try using this code
NSString *deviceType = [UIDevice currentDevice].model;
NSLog(@"DEVICE TYPE %@", deviceType);
check out this LINK
Hope this helps
-
1
-
Your code just give device type i.e. iPhone , iPad not giving different device name i.e. iPhone 5s,iPhone 4s ,iPhone 5. – Birju Oct 31 '15 at 09:20