Last active
December 24, 2015 01:29
-
-
Save tuoxie007/6723865 to your computer and use it in GitHub Desktop.
Detect iOS device version
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
+ (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"]) return @"iPhone 1G"; | |
if ([platform hasPrefix:@"iPhone1"]) return @"iPhone 3G"; | |
if ([platform hasPrefix:@"iPhone2"]) return @"iPhone 3GS"; | |
if ([platform hasPrefix:@"iPhone3"]) return @"iPhone 4"; | |
if ([platform hasPrefix:@"iPhone4"]) return @"iPhone 4s"; | |
if ([platform hasPrefix:@"iPhone5,1"]) return @"iPhone 5"; | |
if ([platform hasPrefix:@"iPhone5,2"]) return @"iPhone 5"; | |
if ([platform hasPrefix:@"iPhone5,3"]) return @"iPhone 5c"; | |
if ([platform hasPrefix:@"iPhone5,4"]) return @"iPhone 5c"; | |
if ([platform hasPrefix:@"iPhone6"]) return @"iPhone 5c"; | |
if ([platform hasPrefix:@"iPod1"]) return @"iPod touch 1G"; | |
if ([platform hasPrefix:@"iPod2"]) return @"iPod touch 2G"; | |
if ([platform hasPrefix:@"iPod3"]) return @"iPod touch 3G"; | |
if ([platform hasPrefix:@"iPod4"]) return @"iPod touch 4G"; | |
if ([platform hasPrefix:@"iPod5"]) return @"iPod touch 5G"; | |
if ([platform hasPrefix:@"iPad1"]) return @"iPad"; | |
if ([platform hasPrefix:@"iPad2,1"]) return @"iPad 2"; | |
if ([platform hasPrefix:@"iPad2,2"]) return @"iPad 2"; | |
if ([platform hasPrefix:@"iPad2,3"]) return @"iPad 2"; | |
if ([platform hasPrefix:@"iPad2,4"]) return @"iPad 2"; | |
if ([platform hasPrefix:@"iPad2,5"]) return @"iPad mini"; | |
if ([platform hasPrefix:@"iPad2,6"]) return @"iPad mini"; | |
if ([platform hasPrefix:@"iPad2,7"]) return @"iPad mini"; | |
if ([platform hasPrefix:@"iPad3"]) return @"iPad 3"; | |
if ([platform hasPrefix:@"iPad4"]) return @"iPad 4"; | |
if ([platform hasPrefix:@"i386"]) return @"Simulator"; | |
if ([platform hasPrefix:@"x86_64"]) return @"Simulator"; | |
return platform; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment