I've got an ipad app with some pretty small touch points that are just barely acceptable on the 10 inch screen of a normal ipad. I'd like to be able to get the device dpi so I can scale up the size of the small elements for the mini and whatever future mini's that are released.
Asked
Active
Viewed 5,954 times
7
-
[This answer](http://stackoverflow.com/a/7922666/759019) might help. – Anirudh Ramanathan Nov 01 '12 at 13:38
-
possible duplicate of [Get ppi of iPhone / iPad / iPod Touch at runtime](http://stackoverflow.com/questions/3860305/get-ppi-of-iphone-ipad-ipod-touch-at-runtime) – Brian Diggs Nov 01 '12 at 19:57
-
None of both answers handles iPadMini – AlexWien Mar 31 '13 at 16:19
2 Answers
5
The DPI is 163 pixels per inch (ppi):
http://www.apple.com/ipad-mini/specs/
You cannot get this programmatically, so you will need to store as a constant in your code.

Naveen Kumar Alone
- 7,536
- 5
- 36
- 57

woz
- 10,888
- 3
- 34
- 64
3
You cannot get the dpi (or more correctly ppi) value directly, because you have to know the number of milimeters (or inches) of the physical screen.
You first have to detect whether it is an iPad mini or not, and then you store the dpi value for each (yet known) device in your app.
As time of writing, this code detects iPad mini:
#include <sys/utsname.h>
NSString *machineName()
{
struct utsname systemInfo;
if (uname(&systemInfo) < 0) {
return nil;
} else {
return [NSString stringWithCString:systemInfo.machine
encoding:NSUTF8StringEncoding];
}
}
// detects iPad mini by machine id
+ (BOOL) isIpadMini {
NSString *machName = machineName();
if (machName == nil) return NO;
BOOL isMini = NO;
if ( [machName isEqualToString:@"iPad2,5"]
|| [machName isEqualToString:@"iPad2,6"]
|| [machName isEqualToString:@"iPad2,7"])
{
isMini = YES;
}
return isMini;
}
It's not futureproof because a new machine id might be introduced later, but there is no futureproof method.
If it is an iPad mini use 163 dpi, otherwise use the links above in the comment, to calculate dpi for iPhone and iPad.

AlexWien
- 28,470
- 6
- 53
- 83