How to distinguish between ipad mini and ipad air?

When I run the ipad mini simulator (which I use the ipad 2 profile) and ipad air, it shows the same resolution of 1024x768

for UI Kit it can be configured automatically, but I use cocos2d

+1
source share
3 answers

Apple really does not want you to be able to detect this, so they did not provide an easy way to do this. I think you really should ask yourself why you need to know.

However, I happen to have a β€œlinear application,” which is probably one of the few legitimate reasons to treat the mini differently. I put this in a category in UIDevice

interface:

// UIDevice+JEFkit.h typedef NS_ENUM (NSUInteger, deviceClass) { deviceClass_iPhone = 0, deviceClass_iPhoneTall = 1, deviceClass_iPhoneSix = 2, deviceClass_iPhoneSixPlus= 3, deviceClass_iPadMini = 10, deviceClass_iPad = 11, deviceClass_unknown }; @interface UIDevice (JEFkit) #pragma mark device type.. +(deviceClass )deviceClass; //some other stuff.. @end 

implementation:

 +(deviceClass )deviceClass{ NSUInteger greater = ((NSUInteger )fmaxf([[UIScreen mainScreen]bounds].size.width, [[UIScreen mainScreen]bounds].size.height)); switch (greater) { case 480: return deviceClass_iPhone; break; case 568: return deviceClass_iPhoneTall; break; case 667: return deviceClass_iPhoneSix; break; case 736: return deviceClass_iPhoneSixPlus; break; case 1024: // its an ipad, what size ? { size_t size1; sysctlbyname("hw.machine", NULL, &size1, NULL, 0); char *machine1 = malloc(size1 + 1); sysctlbyname("hw.machine", machine1, &size1, NULL, 0); machine1[size1] = 0; if (strcmp(machine1, "iPad1,1") == 0 || strcmp(machine1, "iPad2,1") == 0 || strcmp(machine1, "iPad2,2") == 0 || strcmp(machine1, "iPad2,3") == 0 || strcmp(machine1, "iPad2,4") == 0 ) { /* iPad 1 or 2 */ free(machine1); return deviceClass_iPad; } if ([[UIScreen mainScreen]respondsToSelector:@selector(scale)]) { if ([[UIScreen mainScreen] scale] < 2.0) { free(machine1); return deviceClass_iPadMini; //all other non-retina full sized iPad devices are eliminated, must be first GEN mini /// nb the iPad simulator also in here.. } }else{ ///does not respond to @selector(scale) /// should not ever happen free(machine1); return deviceClass_iPad; } //ok only retina ipads are left... if (strcmp(machine1, "iPad4,4") == 0 || strcmp(machine1, "iPad4,5") == 0 || strcmp(machine1, "iPad4,6") == 0 || strcmp(machine1, "iPad4,7") == 0 || strcmp(machine1, "iPad4,8") == 0 || strcmp(machine1, "iPad4,9") == 0) { /* 2nd/3rd gen minis w retina*/ ////TODO//// /// future retina minis !!! /// free(machine1); return deviceClass_iPadMini; } //known retina minis are eliminated.. free(machine1); return deviceClass_iPad; } break; default: break; } return deviceClass_unknown; } 
+4
source

You can use the model method in the UIDevice class for different devices. What more, you can use this open source framework https://github.com/erichoracek/UIDevice-Hardware . It may be more convenient to use.

0
source

If you have a question about retina versus non-retina, then UIScreen has many methods for querying screen parameters (for example, [UIScreen scale]).

But if you want to handle the difference in dpi (and the corresponding minimum button size), please see Detect device (iPhone, iPod Touch) with iPhone SDK . Warning: the device list is open, so whenever a new device appears, you will need to update your application.

-1
source

All Articles