Last active
October 4, 2015 13:28
-
-
Save ishida/2645043 to your computer and use it in GitHub Desktop.
Determine iPhone, iPod touch and iPad model generations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <sys/sysctl.h> | |
/* | |
Return device model name. | |
Possible values: | |
"iPhone1,1" = iPhone 1G | |
"iPhone1,2" = iPhone 3G | |
"iPhone2,1" = iPhone 3GS | |
"iPhone3,1" = iPhone 4 | |
"iPhone3,3" = iPhone 4 (CDMA) | |
"iPhone4,1" = iPhone 4S | |
"iPhone5,1" = iPhone 5 | |
"iPod1,1" = iPod touch 1G | |
"iPod2,1" = iPod touch 2G | |
"iPod3,1" = iPod touch 3G | |
"iPod4,1" = iPod touch 4G | |
"iPad1,1" = iPod | |
"iPad2,1" = iPod 2 (WiFi) | |
"iPad2,2" = iPod 2 (GSM) | |
"iPad2,3" = iPod 2 (CDMAV) | |
"iPad2,4" = iPod 2 (CDMAS) | |
"iPad3,1" = iPod 3 | |
"iPad3,2" = iPod 3 (GSM+CDMA) | |
"iPad3,3" = iPod 3 (GSM) | |
"AppleTV2,1" = Apple TV (2G) | |
"AppleTV3,1" = Apple TV (3G) | |
"i386" = Simulator | |
"x86_64" = Simulator | |
*/ | |
- (NSString *)machineName | |
{ | |
size_t size; | |
sysctlbyname("hw.machine", NULL, &size, NULL, 0); | |
char *tmpMachine = malloc(size); | |
sysctlbyname("hw.machine", tmpMachine, &size, NULL, 0); | |
NSString *machine = [NSString stringWithCString:tmpMachine encoding: NSUTF8StringEncoding]; | |
free(tmpMachine); | |
return machine; | |
} | |
- (BOOL)isIphone4 | |
{ | |
return [[self machineName] hasPrefix:@"iPhone3,"]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment