I am trying to figure out a simple way of knowing what is my Device type.
I already know about
[[UIDevice currentDevice] systemVersion]
which give me the general type.
But what I really need is to now wether it is 4, 4S, 5 or any other type of iPhone.
you can get your platform and device type by using this method
- (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;
}
Hi use this class for get Device types and Device Version from this bellow link..
UIDeviceHardware
just read the instruction that how to use and how to get the platform...
Here you got response like for Example... Verizon iPhone 4,iPhone 4S,iPod Touch 1G,iPod Touch 2G,etc..
i hope this helpful to you...
I updated the list with the currently available devices. I suggest to make a category on UIDevice, let's call it UIDevice+Platform, and add the following two methods:
- (NSString *)rawPlatform
{
static NSString *platform = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
size_t size;
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
char *machine = malloc(size);
sysctlbyname("hw.machine", machine, &size, NULL, 0);
platform = [NSString stringWithUTF8String:machine];
free(machine);
});
return platform;
}
- (NSString *)exactModel
{
static NSString *platform = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
platform = [self rawPlatform];
if ([platform isEqualToString:#"iPhone1,1"])
platform = #"iPhone 1G";
else if ([platform isEqualToString:#"iPhone1,2"])
platform = #"iPhone 3G";
else if ([platform isEqualToString:#"iPhone2,1"])
platform = #"iPhone 3GS";
else if ([platform isEqualToString:#"iPhone3,1"])
platform = #"iPhone 4";
else if ([platform isEqualToString:#"iPhone3,3"])
platform = #"Verizon iPhone 4";
else if ([platform isEqualToString:#"iPhone4,1"])
platform = #"iPhone 4S";
else if ([platform isEqualToString:#"iPhone5,1"])
platform = #"iPhone 5";
else if ([platform isEqualToString:#"iPhone5,2"])
platform = #"iPhone 5 (GSM+CDMA)";
else if ([platform isEqualToString:#"iPhone5,3"])
platform = #"iPhone 5C";
else if ([platform isEqualToString:#"iPhone5,4"])
platform = #"iPhone 5C (GSM+CDMA)";
else if ([platform isEqualToString:#"iPhone6,1"])
platform = #"iPhone 5S";
else if ([platform isEqualToString:#"iPhone6,2"])
platform = #"iPhone 5S (GSM+CDMA)";
else if ([platform isEqualToString:#"iPhone7,1"])
platform = #"iPhone 6+";
else if ([platform isEqualToString:#"iPhone7,2"])
platform = #"iPhone 6";
else if ([platform isEqualToString:#"iPod1,1"])
platform = #"iPod Touch 1G";
else if ([platform isEqualToString:#"iPod2,1"])
platform = #"iPod Touch 2G";
else if ([platform isEqualToString:#"iPod3,1"])
platform = #"iPod Touch 3G";
else if ([platform isEqualToString:#"iPod4,1"])
platform = #"iPod Touch 4G";
else if ([platform isEqualToString:#"iPod5,1"])
platform = #"iPod Touch 5G";
else if ([platform isEqualToString:#"iPad1,1"])
platform = #"iPad 1";
else if ([platform isEqualToString:#"iPad2,1"])
platform = #"iPad 2 (WiFi)";
else if ([platform isEqualToString:#"iPad2,2"])
platform = #"iPad 2 (GSM)";
else if ([platform isEqualToString:#"iPad2,3"])
platform = #"iPad 2 (CDMA)";
else if ([platform isEqualToString:#"iPad2,1"])
platform = #"iPad 2 (WiFi)";
else if ([platform isEqualToString:#"iPad2,2"])
platform = #"iPad 2 (GSM)";
else if ([platform isEqualToString:#"iPad2,3"])
platform = #"iPad 2 (CDMA)";
else if ([platform isEqualToString:#"iPad2,4"])
platform = #"iPad 2";
else if ([platform isEqualToString:#"iPad2,5"])
platform = #"iPad Mini (Wifi)";
else if ([platform isEqualToString:#"iPad2,6"])
platform = #"iPad Mini";
else if ([platform isEqualToString:#"iPad2,7"])
platform = #"iPad Mini (GSM+CDMA)";
else if ([platform isEqualToString:#"iPad3,1"])
platform = #"iPad 3 (WiFi)";
else if ([platform isEqualToString:#"iPad3,2"])
platform = #"iPad 3 (GSM+CDMA)";
else if ([platform isEqualToString:#"iPad3,3"])
platform = #"iPad 3 (4G,3)";
else if ([platform isEqualToString:#"iPad3,4"])
platform = #"iPad 4 (WiFi)";
else if ([platform isEqualToString:#"iPad3,5"])
platform = #"iPad 4 (4G,2)";
else if ([platform isEqualToString:#"iPad3,6"])
platform = #"iPad 4 (GSM+CDMA)";
else if ([platform isEqualToString:#"iPad4,1"])
platform = #"iPad Air (Wifi)";
else if ([platform isEqualToString:#"iPad4,2"])
platform = #"iPad Air (GSM+CDMA)";
else if ([platform isEqualToString:#"iPad4,3"])
platform = #"iPad Air";
else if ([platform isEqualToString:#"iPad4,4"])
platform = #"iPad Mini 2 (GSM)";
else if ([platform isEqualToString:#"iPad4,5"])
platform = #"iPad Mini 2 (CDMA)";
else if ([platform isEqualToString:#"iPad4,6"])
platform = #"iPad Mini 2 (Wifi)";
else if ([platform isEqualToString:#"iPad4,7"])
platform = #"iPad Mini 3 (Wifi)";
else if ([platform isEqualToString:#"iPad4,8"])
platform = #"iPad Mini 3 (GSM+CDMA)";
else if ([platform isEqualToString:#"iPad4,9"])
platform = #"iPad Mini 3";
else if ([platform isEqualToString:#"iPad5,3"])
platform = #"iPad Air 2 (Wifi)";
else if ([platform isEqualToString:#"iPad5,4"])
platform = #"iPad Air 2 (GSM+CDMA)";
else if ([platform isEqualToString:#"i386"])
platform = #"Simulator";
else if ([platform isEqualToString:#"x86_64"])
platform = #"Simulator";
});
return platform;
}
In the UIDevice Class a property to find out type of iPhone:
#property(nonatomic,readonly,retain) NSString *systemVersion; // e.g. #"4.0"
Related
I need a quick way to identify A5/A4 based iOS 7 devices (iPhone 4S and below). I can not rely on UIScreen bounds as iPod touch 5g also has same A5 processor as iPhone 4S. I need it to determine the processing capability.
You can distinguish devices with this code
+ (NSString *) platform
{
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;
}
+ (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 containsString:#"iPhone5"]) return #"iPhone 5";
if ([platform containsString:#"iPhone6"]) return #"iPhone 5S";
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";
if ([platform isEqualToString:#"iPad2,5"]) return #"iPad Mini";
if ([platform isEqualToString:#"iPad2,6"]) return #"iPad Mini";
if ([platform isEqualToString:#"iPad2,7"]) return #"iPad Mini )";
if ([platform isEqualToString:#"iPad3,1"]) return #"iPad 3";
if ([platform isEqualToString:#"iPad3,2"]) return #"iPad 3";
if ([platform isEqualToString:#"iPad3,3"]) return #"iPad 3";
if ([platform isEqualToString:#"iPad3,4"]) return #"iPad 4";
if ([platform isEqualToString:#"iPad3,5"]) return #"iPad 4";
if ([platform isEqualToString:#"iPad3,6"]) return #"iPad 4";
if ([platform isEqualToString:#"iPad4,1"]) return #"iPad Air";
if ([platform isEqualToString:#"iPad4,2"]) return #"iPad Air";
if ([platform isEqualToString:#"iPad4,4"]) return #"iPad mini";
if ([platform isEqualToString:#"iPad4,5"]) return #"iPad mini";
if ([platform isEqualToString:#"i386"]) return #"Simulator";
if ([platform isEqualToString:#"x86_64"]) return #"Simulator";
return #"iOS Device";
}
what will be the output of the following code:
NSString *deviceType = [UIDevice currentDevice].model;
NSLog(#"Device Type: %#", deviceType);
in iPhone 4, it will print "iPhone" but in iPhone 4S or iPhone 5 what will be the output? I don't have iPhone 4S or 5 device. But I need to know it for implementing calling feature in all the versions of iPhones.
thanks.
in iPhone 4, it will print "iPhone" but in iPhone 4S or iPhone 5 what will be the output?
Also "iPhone".
(documentation.)
UIDevice isnt helpful use
#include <sys/types.h>
#include <sys/sysctl.h>
- (NSString *)deviceModel
{
NSString *deviceModel = nil;
char buffer[32];
size_t length = sizeof(buffer);
if (sysctlbyname("hw.machine", &buffer, &length, NULL, 0) == 0) {
deviceModel = [[NSString alloc] initWithCString:buffer encoding:NSASCIIStringEncoding];
}
return [deviceModel autorelease];
}
I also dont know the constant for the 5 but I know they are unique:
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:#"iPad2,4"]) return #"iPad 2";
if ([platform isEqualToString:#"iPad3,1"]) return #"iPad-3G (WiFi)";
if ([platform isEqualToString:#"iPad3,2"]) return #"iPad-3G (4G)";
if ([platform isEqualToString:#"iPad3,3"]) return #"iPad-3G (4G)";
if ([platform isEqualToString:#"i386"]) return #"Simulator";
if ([platform isEqualToString:#"x86_64"]) return #"Simulator";
Phone 5 GSM - iPhone5,1
iPhone 5 CDMA - iPhone5,2
iPod 5 - iPod5,1
Info taken from the iOS file names. Please check http://osxdaily.com/2012/09/19/ios-6-ipsw-direct-download-links/
If you are trying to differentiate between iPhone4/4S & iPhone5, you should check the screen size, not the device model.
For example, is it "iPhone5,1" or "iPhone5,2" for iPhone 5? And what's the difference?
If anyone has the iPhone 5, please help by running the following code and showing your result. Thank you.
Related Link: https://stackoverflow.com/a/3950748/482899
You can find a list of all iOS device identifiers here (including iPhone 5 models and iPad mini):
http://theiphonewiki.com/wiki/index.php?title=Models
The identifiers of the latest models are:
iPhone 5: iPhone5,1 and iPhone5,2
iPhone 5C: iPhone5,3 and iPhone5,4
iPhone 5S: iPhone6,1 and iPhone6,2
iPhone 6: iPhone7,2
iPhone 6 Plus: iPhone7,1
iPhone 6S: iPhone8,1
iPhone 6S Plus: iPhone8,2
iPhone SE: iPhone8,4
iPhone 7: iPhone9,1 and iPhone9,3
iPhone 7 Plus: iPhone9,2 and iPhone9,4
iPhone 8: iPhone10,1 and iPhone10,4
iPhone 8 Plus: iPhone10,2 and iPhone10,5
iPhone X: iPhone10,3 and iPhone10,6
EDIT: I also made an updated version of the popular iOS Support Matrix including all models up to iPhone X.
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:#"iPhone5,3"]) return #"iPhone 5c (GSM+CDMA)";
if ([platform isEqualToString:#"iPhone5,4"]) return #"iPhone 5c (UK+Europe+Asia+China)";
if ([platform isEqualToString:#"iPhone6,1"]) return #"iPhone 5s (GSM+CDMA)";
if ([platform isEqualToString:#"iPhone6,2"]) return #"iPhone 5s (UK+Europe+Asia+China)";
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 (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:#"iPod7,1"]) return #"iPod Touch (6 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:#"iPad4,1"]) return #"iPad Air (WiFi)";
if ([platform isEqualToString:#"iPad4,2"]) return #"iPad Air (GSM+CDMA)";
if ([platform isEqualToString:#"iPad4,4"]) return #"iPad Mini 2 (WiFi)";
if ([platform isEqualToString:#"iPad4,5"]) return #"iPad Mini 2 (GSM+CDMA)";
if ([platform isEqualToString:#"iPad4,6"]) return #"iPad Mini 2 (China)";
if ([platform isEqualToString:#"iPad4,7"]) return #"iPad Mini 3 (WiFi)";
if ([platform isEqualToString:#"iPad4,8"]) return #"iPad Mini 3 (GSM+CDMA)";
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";
if ([platform isEqualToString:#"i386"]) return #"Simulator";
if ([platform isEqualToString:#"x86_64"]) return #"Simulator";
return platform;
This method covers all devices in market:
- (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; }
- (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+CDMA)";
if ([platform isEqualToString:#"iPhone5,4"]) return #"iPhone 5c (UK+Europe+Asia+China)";
if ([platform isEqualToString:#"iPhone6,1"]) return #"iPhone 5s (GSM+CDMA)";
if ([platform isEqualToString:#"iPhone6,2"]) return #"iPhone 5s (UK+Europe+Asia+China)";
if ([platform isEqualToString:#"iPhone7,1"]) return #"iPhone 6 Plus";
if ([platform isEqualToString:#"iPhone7,2"]) return #"iPhone 6";
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:#"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:#"iPad4,1"]) return #"iPad Air (WiFi)";
if ([platform isEqualToString:#"iPad4,2"]) return #"iPad Air (Cellular)";
if ([platform isEqualToString:#"iPad4,4"]) return #"iPad Mini 2 (WiFi)";
if ([platform isEqualToString:#"iPad4,5"]) return #"iPad Mini 2 (Cellular)";
if ([platform isEqualToString:#"iPad4,6"]) return #"iPad Mini 2";
if ([platform isEqualToString:#"iPad4,7"]) return #"iPad Mini 3";
if ([platform isEqualToString:#"iPad4,8"]) return #"iPad Mini 3";
if ([platform isEqualToString:#"iPad4,9"]) return #"iPad Mini 3";
if ([platform isEqualToString:#"iPad5,3"]) return #"iPad Air 2";
if ([platform isEqualToString:#"iPad5,4"]) return #"iPad Air 2";
if ([platform isEqualToString:#"i386"]) return #"Simulator";
if ([platform isEqualToString:#"x86_64"]) return #"Simulator";
return platform; }
Yup, "iPhone5,1" is the GSM iPhone 5, "iPhone5,2" is the CDMA iPhone 5, "iPhone5,3" is the GSM iPhone 5C, "iPhone5,4" is the CDMA iPhone 5C, "iPhone6,1" is the GSM iPhone 5S, and "iPhone6,2" is the CDMA iPhone 5S. Does that answer your question?
It looks like either iPhone5,1 or iPhone5,2 depending on the model of iPhone 5.
From #marcoarment, who is a well known iOS Developer:
iPhone5,1: model A1428, AT&T/Canada
iPhone5,2: model A1429, all others
A1429 may have two modes, but I don’t see any iPhone5,3 records.
Source: https://twitter.com/marcoarment/status/249249183029161984
The Verizon iPhone 5 returns "iPhone5,2". The GSM phone returns "iPhone5,1".
I created a library for detecting the device at runtime.
It's called SDVersion.
Thought some may found it useful.
[Update]
iPhone10,1 : iPhone 8
iPhone10,2 : iPhone 8 Plus
iPhone10,3 : iPhone X Global
iPhone10,4 : iPhone 8
iPhone10,5 : iPhone 8 Plus
iPhone10,6 : iPhone X GSM
iPhone11,2 : iPhone XS
iPhone11,4 : iPhone XS Max
iPhone11,6 : iPhone XS Max Global
iPhone11,8 : iPhone XR
iPhone12,1 : iPhone 11
iPhone12,3 : iPhone 11 Pro
iPhone12,5 : iPhone 11 Pro Max
iPhone12,8 : iPhone SE 2nd Gen
check out your answer over here How to detect iPhone 5 (widescreen devices)?. till now i have not found any answer until some one developer buy iPhone 5 and post some useful information
How do I detect if a user is running the application on an iPhone 4 or 3G/3GS?
I need to detect the hardware, not the iOS version.
thanks for any help.
feel free to use this class - I found it here
Usage
UIDeviceHardware *h=[[UIDeviceHardware alloc] init];
[self setDeviceModel:[h platformString]];
[h release];
UIDeviceHardware.h
//
// UIDeviceHardware.h
//
// Used to determine EXACT version of device software is running on.
#import <Foundation/Foundation.h>
#interface UIDeviceHardware : NSObject
- (NSString *) platform;
- (NSString *) platformString;
#end
UIDeviceHardware.m
//
// UIDeviceHardware.m
//
// Used to determine EXACT version of device software is running on.
#import "UIDeviceHardware.h"
#include <sys/types.h>
#include <sys/sysctl.h>
#implementation UIDeviceHardware
- (NSString *) platform{
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];
free(machine);
return platform;
}
- (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:#"iPod1,1"]) return #"iPod Touch 1G";
if ([platform isEqualToString:#"iPod2,1"]) return #"iPod Touch 2G";
if ([platform isEqualToString:#"i386"]) return #"iPhone Simulator";
return platform;
}
#end
#import <sys/utsname.h>
+ (NSString*)deviceModelName {
struct utsname systemInfo;
uname(&systemInfo);
NSString *modelName = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
if([modelName isEqualToString:#"i386"]) {
modelName = #"iPhone Simulator";
}
else if([modelName isEqualToString:#"iPhone1,1"]) {
modelName = #"iPhone";
}
else if([modelName isEqualToString:#"iPhone1,2"]) {
modelName = #"iPhone 3G";
}
else if([modelName isEqualToString:#"iPhone2,1"]) {
modelName = #"iPhone 3GS";
}
else if([modelName isEqualToString:#"iPhone3,1"]) {
modelName = #"iPhone 4";
}
else if([modelName isEqualToString:#"iPhone4,1"]) {
modelName = #"iPhone 4S";
}
else if([modelName isEqualToString:#"iPod1,1"]) {
modelName = #"iPod 1st Gen";
}
else if([modelName isEqualToString:#"iPod2,1"]) {
modelName = #"iPod 2nd Gen";
}
else if([modelName isEqualToString:#"iPod3,1"]) {
modelName = #"iPod 3rd Gen";
}
else if([modelName isEqualToString:#"iPad1,1"]) {
modelName = #"iPad";
}
else if([modelName isEqualToString:#"iPad2,1"]) {
modelName = #"iPad 2(WiFi)";
}
else if([modelName isEqualToString:#"iPad2,2"]) {
modelName = #"iPad 2(GSM)";
}
else if([modelName isEqualToString:#"iPad2,3"]) {
modelName = #"iPad 2(CDMA)";
}
return modelName;
}
You can use this code for detecting iPhone OS version.
float version = [[[UIDevice currentDevice] systemVersion] floatValue];
if (version >= 3.0) {
// Only executes on version 3 or above.
}
I want to identify the device on which my application is installed.
That means, when I install the app on the iphone, it should tell me the device information.
The information is like, the device is 2G, 3G or 3GS.
Currently I am getting only model, name, systemName, systemVersion of the device.
I want to know the device is 2G , 3G or 3GS.
please help me.
In the past history of Mac programming, this was always considered the wrong question.
What you really need to know is a more specific piece of information. Ask a much more narrow question for each behavioral decision in your code. For example, you may need to know if the device has GPS or not. Another is that you shouldn't decide how to use the OpenGL stack based on what model device it is, but rather on the OpenGL capabilities/extensions information that is provided.
The information you're getting now is from UIDevice, which is an unfortunately poorly designed API. It provides you with exactly the wrong information in the worst possible format -- strings.
Erica Sadun has an extension to UIDevice that may be useful here. It's just a wrapper for sysctlbyname("hw.machine", ...). This property is different for each model.
But again, this is usually the wrong question.
This is what I used in my app and it works great
NSString *deviceType = [UIDevice currentDevice].model;
NSLog(#"DEVICE TYPE %#", deviceType);
struct utsname systemInfo;
uname(&systemInfo);
- (NSString *) platformString{
NSString *platform = [NSString stringWithCString:systemInfo.machine
encoding:NSUTF8StringEncoding];
NSLog(#"type ...%#", 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:#"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";
return platform;
}
Hope it helps
I made this, it even shows you the model number:
struct utsname systemInfo;
uname(&systemInfo);
NSString *modelName = [NSString stringWithCString:systemInfo.machine
encoding:NSUTF8StringEncoding];
NSString *machinename = [NSString stringWithCString:systemInfo.machine
encoding:NSUTF8StringEncoding];
NSString *modelnumber = #"Not listed";
//Simulator
if([modelName isEqualToString:#"i386"] || [modelName isEqualToString:#"x86_64"]) {
modelName = #"iPhone Simulator";
modelnumber = #"XXXXX";
}
//iPhone
else if([modelName isEqualToString:#"iPhone1,1"]) {
modelName = #"iPhone";
modelnumber = #"A1203";
}
else if([modelName isEqualToString:#"iPhone1,2"]) {
modelName = #"iPhone 3G";
modelnumber = #"A1241/A1324";
}
else if([modelName isEqualToString:#"iPhone2,1"]) {
modelName = #"iPhone 3GS";
modelnumber = #"A1303/A1325";
}
else if([modelName isEqualToString:#"iPhone3,1"]) {
modelName = #"iPhone 4 (GSM)";
modelnumber = #"A1332";
}
else if([modelName isEqualToString:#"iPhone3,2"]) {
modelName = #"iPhone 4 GSM Rev A";
modelnumber = #"Not listed";
}
else if([modelName isEqualToString:#"iPhone3,3"]) {
modelName = #"iPhone 4 (CDMA)";
modelnumber = #"A1349";
}
else if([modelName isEqualToString:#"iPhone4,1"]) {
modelName = #"iPhone 4S";
modelnumber = #"A1387/A1431";
}
else if([modelName isEqualToString:#"iPhone5,1"]) {
modelName = #"iPhone 5 (GSM)";
modelnumber = #"A1428";
}
else if([modelName isEqualToString:#"iPhone5,2"]) {
modelName = #"iPhone 5 (GSM+CDMA)";
modelnumber = #"A1429/A1442";
}
//iPod touch
else if([modelName isEqualToString:#"iPod1,1"]) {
modelName = #"iPod touch 1G";
modelnumber = #"A1213";
}
else if([modelName isEqualToString:#"iPod2,1"]) {
modelName = #"iPod touch 2G";
modelnumber = #"A1288";
}
else if([modelName isEqualToString:#"iPod3,1"]) {
modelName = #"iPod touch 3G";
modelnumber = #"A1318";
}
else if([modelName isEqualToString:#"iPod4,1"]) {
modelName = #"iPod touch 4G";
modelnumber = #"A1367";
}
else if([modelName isEqualToString:#"iPod5,1"]) {
modelName = #"iPod touch 5G";
modelnumber = #"A1421";
}
//iPad
else if([modelName isEqualToString:#"iPad1,1"]) {
modelName = #"iPad 1G";
modelnumber = #"A1219/A1337";
}
else if([modelName isEqualToString:#"iPad2,1"]) {
modelName = #"iPad 2 (WiFi)";
modelnumber = #"A1395";
}
else if([modelName isEqualToString:#"iPad2,2"]) {
modelName = #"iPad 2 (GSM)";
modelnumber = #"A1396";
}
else if([modelName isEqualToString:#"iPad2,3"]) {
modelName = #"iPad 2 (CDMA)";
modelnumber = #"A1397";
}
else if([modelName isEqualToString:#"iPad2,4"]) {
modelName = #"iPad 2 (WiFi + Rev A)";
modelnumber = #"A1395";
}
else if([modelName isEqualToString:#"iPad3,1"]) {
modelName = #"iPad 3 (WiFi)";
modelnumber = #"A1416";
}
else if([modelName isEqualToString:#"iPad3,2"]) {
modelName = #"iPad 3 (GSM+CDMA)";
modelnumber = #"A1403";
}
else if([modelName isEqualToString:#"iPad3,3"]) {
modelName = #"iPad 3 (GSM)";
modelnumber = #"A1430";
}
else if([modelName isEqualToString:#"iPad3,4"]) {
modelName = #"iPad 4 (WiFi)";
modelnumber = #"A1458";
}
else if([modelName isEqualToString:#"iPad3,5"]) {
modelName = #"iPad 4 (GSM)";
modelnumber = #"A1459";
}
else if([modelName isEqualToString:#"iPad3,6"]) {
modelName = #"iPad 4 (GSM+CDMA)";
modelnumber = #"A1460";
}
//iPad mini
else if([modelName isEqualToString:#"iPad2,5"]) {
modelName = #"iPad mini (WiFi)";
modelnumber = #"A1432";
}
else if([modelName isEqualToString:#"iPad2,6"]) {
modelName = #"iPad mini (GSM)";
modelnumber = #"A1454";
}
else if([modelName isEqualToString:#"iPad2,7"]) {
modelName = #"iPad mini (GSM+CDMA)";
modelnumber = #"A1455";
}
//Apple TV, just for funn:)
else if([modelName isEqualToString:#"AppleTV2,1"]) {
modelName = #"Apple TV 2G";
modelnumber = #"A1378";
}
else if([modelName isEqualToString:#"AppleTV3,1"]) {
modelName = #"Apple TV 3G";
modelnumber = #"A1427";
}
else if([modelName isEqualToString:#"AppleTV3,2"]) {
modelName = #"Apple TV 3G (Rev A)";
modelnumber = #"A1469";
}
NSLog(#"Device model: %#/ %# /%#",modelName,machinename,modelnumber);