johnbakers
johnbakers

Reputation: 24770

Best way to get type of iOS device in the codee

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?

Upvotes: 0

Views: 566

Answers (1)

DarkDust
DarkDust

Reputation: 92345

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.
}

Upvotes: 3

Related Questions