Created
July 9, 2012 00:38
-
-
Save baz/3073573 to your computer and use it in GitHub Desktop.
PPI of iOS device
This file contains hidden or 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
float screenResolution() { | |
struct utsname systemInfo; | |
uname(&systemInfo); | |
char *name = systemInfo.machine; | |
float ppi; | |
if ((strstr(name, "iPod") != NULL) && (strstr(name, "iPod4") == NULL)) { | |
// older ipod touches | |
ppi = 163; | |
} else if ((strstr(name, "iPhone") != NULL) && (strstr(name, "iPhone3") == NULL)) { | |
// older non-retina iphones | |
ppi = 163; | |
} else if ((strstr(name, "iPad") != NULL) && (strstr(name, "iPad3") == NULL)) { | |
// ipad 1, ipad 2 | |
ppi = 132; | |
} else if (strstr(name, "iPad3") != NULL) { | |
// ipad 3 | |
ppi = 264; | |
} else { | |
// iphone 4/4s, ipod touch 4g or simulator | |
ppi = 326; | |
} | |
return ppi; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment