7
votes

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.

2
None of both answers handles iPadMiniAlexWien

2 Answers

5
votes

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.

3
votes

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.