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 informat
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);
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