8

Possible Duplicate:
Dealing with iPad Mini screen size
Is it possible to detect that your iOS app is running on an iPad mini at runtime?

iPad mini has the same resolution as iPad 1(2) (1024x768).

But iPad mini has 7,9 inches, and iPad 1(2) - 9,7 inches.

So the question is how to check if device is Ipad mini.

Community
  • 1
  • 1
Buron
  • 1,193
  • 2
  • 13
  • 23

2 Answers2

16

This answer contains a link to an utility method to get a "platform string" that can be used to identify the various iOS devices. I copy the main method here for your convenience:

#include <sys/types.h>
#include <sys/sysctl.h>

- (NSString *) platform {
    size_t size;
    sysctlbyname("hw.machine", NULL, &size, NULL, 0);
    char *machine = malloc(size);
    sysctlbyname("hw.machine", machine, &size, NULL, 0);
    NSString *platform = [NSString stringWithUTF8String:machine];
    free(machine);
    return platform;
}

According to Models - The iPhone Wiki, the return value of platform is one of

  • iPad2,5
  • iPad2,6
  • iPad2,7

for an iPad mini.

Community
  • 1
  • 1
Martin R
  • 529,903
  • 94
  • 1,240
  • 1,382
1

Apple's view is probably that you don't need to know this. :( Your app behaves in every respect exactly the same on an iPad 1 or 2 screen and an iPad mini screen. As far as pixels are concerned they are the same size.

And every other aspect of the device, such as its hardware capabilities (e.g. does it have a camera?) can be checked in the normal way, through the appropriate API for using that hardware.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • 2
    If the screen is the same resolution but physically smaller, how can the pixels be the same size? – rmaddy Nov 24 '12 at 18:46
  • I didn't say the pixels were the same size. I said the devices were the same size as measured in pixels. - The point is that it doesn't matter what size they are, as far as Apple is concerned, because there is no part of the iOS API that refers to pixel size! In fact, there is no part of the API that refers to pixels at all. You program in points, they are translated to pixels on the device. – matt Nov 24 '12 at 18:49
  • The last sentence of the first paragraph is what confused me. No biggie. In general I agree. The only time DPI matters is if an app needs to draw something to a specific physical size (like a ruler). – rmaddy Nov 24 '12 at 18:56
  • I completely agree about the ruler. That is why I said "Apple's view" and "as far as Apple is concerned". I agree that they *should* give you a way to learn the physical pixel size, so you can make a ruler app. But they don't, because (as I said) they don't think you need this information. If you disagree with Apple, you should file a bug at bugreporter.apple.com, requesting an API that provides this information. – matt Nov 24 '12 at 19:04
  • 1
    Agree. I have a game where the buttons are too small on an iPad mini only, but no future-proof way of detecting whether the current device is iPad mini or not... So frustrating. – dqhendricks Aug 08 '13 at 23:07
  • 2
    "you don't need to know this" - simply not true. I wish people wouldn't keep making this incorrect point. Case in point: iPad Mini has the same OpenGL texture size as iPad3, but considerably less (half as much?) GPU memory. This means it hard-crashes if you load it up with textures. Apple provides no interface for measuring available memory - you are apparently expected to work out the iPad version and back-calculate how large a texture set to use. – Adam Oct 21 '13 at 23:07
  • I didn't say you don't need to know this. I said Apple seems to think you don't need to know it. I don't agree with Apple. – matt Oct 21 '13 at 23:57
  • 1
    @Adam In iOS 9, that problem is solved through asset catalogs, from which can you can retrieve different textures for different memory configurations, automatically. – matt Jul 17 '15 at 22:13
  • @matt Does that require Apple's texture loader? If so, has Apple finally fixed their texture loader? It was broken in all previous versions of iOS until at least iOS 7 (not tested with 8, but I didnt notice it in release notes). – Adam Jul 17 '15 at 22:41
  • @Adam it involves asset catalogs. I don't know what else it involves; you'd have to watch the WWDC 2015 videos to decide that... – matt Jul 17 '15 at 22:44
  • 1
    Really should edit this answer to be clearer about "As far as pixels are concerned they are the same size". That's an ambiguous sentence, that is confusing many who come here, based on the comments. Anyone who is searching for an answer to this question is doing so because they care about the actual physical size, not the number of pixels. (In my case, because I want a UI element to move out of the way of user's finger touching screen, but the distance to move I base on typical finger size, so should move fewer pixels on this less-dense screen.) The last half of the answer is irrelevant. – ToolmakerSteve Dec 11 '15 at 18:07