How can I detect the dpi on an ipad mini?

这一生的挚爱 提交于 2019-11-30 09:50:29
woz

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.

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!