Although you can use something like this – Get iPhone Device Name, Unique Device Identifier (UDID), OS and Model – to check if your app is running on an iPad, there is a much easier way.
Check the userInterfaceIdiom property of the device to get the information you need:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
- (BOOL)isDeviceiPad { BOOL iPadDevice = NO; // Is userInterfaceIdiom available? if ([[UIDevice currentDevice] respondsToSelector:@selector(userInterfaceIdiom)]) { // Is device an iPad? if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) iPadDevice = YES; } return iPadDevice; } |
As noted in the comments below, Apple provides a macro to accomplish the same task. Here is the full definition from the UIDevice.h header file:
1 |
#define UI_USER_INTERFACE_IDIOM() ([[UIDevice currentDevice] respondsToSelector:@selector(userInterfaceIdiom)] ? [[UIDevice currentDevice] userInterfaceIdiom] : UIUserInterfaceIdiomPhone) |
Thanks for the heads up on this.
or just use this:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) iPadDevice = YES;
UI_USER_INTERFACE_IDIOM() is defined in UIDevice.h and performs the same checks
(write UI_USER_INTERFACE_IDIOM() in your source and Cmd+Click on it to see)
Why not just use
return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad);
There’s a macro for that: UI_USER_INTERFACE_IDIOM()
Check out the talk I gave on making universal apps and the differences between the iPhone and iPad APIs and controls:
https://github.com/markrickert/iPhone-iPad-API-Differences-Tech-Talk
And here’s the presentation:
https://github.com/markrickert/iPhone-iPad-API-Differences-Tech-Talk/raw/master/Presentation/Presentation.pdf