0

I've been doing this, which works just fine, to see if my universal app is running on iPad or iPhone/iPad:

BOOL isIpad=[[UIScreen mainScreen] bounds].size.width<500?NO:YES

Any reason I should not based my test on the UIScreen bounds, or is there a better method?

johnbakers
  • 24,158
  • 24
  • 130
  • 258

1 Answers1

3

Testing for the screen size is a very fragile test. Luckily, Apple already tells you what kind of device you're running on.

For that, use the UI_USER_INTERFACE_IDIOM macro:

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
    // Got an iPad.
} else {
    // == UIUserInterfaceIdiomPhone
    // Got an iPhone or iPod Touch.
}
DarkDust
  • 90,870
  • 19
  • 190
  • 224
  • Any update for how to do an iPhone 5 check? Or do we now need to use the value of [[UIScreen mainScreen] bounds].size.height? Perhaps this should be a new question. But the answer to my question impacts this answer now, so.. – crgt Sep 19 '12 at 23:53
  • 1
    Yes, this is a new question, but so far the answer is indeed to check the height of the mainScreen (at least that's the solution that was quoted in the Apple developer forum over and over again, there's no other reliable and future-proof way to check this). – DarkDust Sep 20 '12 at 13:00