1

When I run on simulator ipad mini (which I am using ipad 2 profile) and ipad air it shows the same resolution 1024x768

for UI Kit it might adjust automatically but I using cocos2d

CodeSmile
  • 64,284
  • 20
  • 132
  • 217
RollRoll
  • 8,133
  • 20
  • 76
  • 135

3 Answers3

4

Apple don't really want you to be able to detect this, so they've not provided an easy way to do it. I think you should really ask yourself why you need to know.

That said, I happen to have a 'ruler app', which is probably one of the very few legitimate reasons to treat the mini differently. I put this in a category on 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;
}
Jef
  • 4,728
  • 2
  • 25
  • 33
0

You can use model method in UIDevice class to distinct different devices. What's more, you can use this open source framework https://github.com/erichoracek/UIDevice-Hardware . It may be more handy to use it.

Xiangyu.Wu
  • 459
  • 1
  • 5
  • 18
  • 2
    If you actually have an iPad mini and try this you'll find it returns an identical result to an iPad ! sorry, bad answer :( – Jef Feb 10 '15 at 05:46
-1

If your question is about retina vs. non-retina then UIScreen has a bunch of methods for querying the screen parameters (e.g [UIScreen scale]).

But if you want to handle the dpi difference (and the related button minimal size) then please have a look at Determine device (iPhone, iPod Touch) with iPhone SDK. Warning though: the list of devices is open, so whenever a new device appears you will have to update your app.

Community
  • 1
  • 1