How to know device type (Simulator, iPhone, iPod, iPad, iPad mini, Apple TV) programmatically ?
OR
How to know device model (iPad1, iPad2... etc) or (iPhone, iPhone4s...etc) programmatically ?
#import <sys/utsname.h>
struct utsname systemInfo;
uname(&systemInfo);
NSString *modelName = [NSString stringWithCString:systemInfo.machine
encoding:NSUTF8StringEncoding];
NSString *machineName = [NSString stringWithCString:systemInfo.machine
encoding:NSUTF8StringEncoding];
NSString *modelNumber = @"?";
//Simulator
if([modelName isEqualToString:@"i386"] || [modelName isEqualToString:@"x86_64"]) {modelName = @"iPhone Simulator";
}
//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 = @"?";
}
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,modelNumber);
I actually enjoyed reading through this posting.Many thanks
ReplyDeleteIphone Application Development
Thanks lolitha !
DeleteThanks for coding. I am new in development, so it will take time to implement. I am enthusiastic to generate a Mobile Apps Development and share with friends.
ReplyDeleteHello,
ReplyDeleteYou came with very nice useful information for the readers.
For iPhone application development in the US people are are consulting iphone app development DC
Regards,
Keith
Useful coding for i phone, i pad. Thanks
ReplyDeleteMobile Apps Developer