Skip to content

Instantly share code, notes, and snippets.

@baz
Created July 9, 2012 00:38
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save baz/3073573 to your computer and use it in GitHub Desktop.
Save baz/3073573 to your computer and use it in GitHub Desktop.
PPI of iOS device
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