Apple advises using the following code to detect whether running on an iPad or iPhone/iPod Touch:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
UI_USER_INTERFACE_IDIOM() and UIUserInterfaceIdiomPad can be used on iOS3.2 and upwards, the important part being the 'upwards'. Sure. iOS3.2 is only for iPad, but iOS4.0 and beyond run on both iPhones and iPads, so the check isn't as pointless as you think.
This is what I use:
- (BOOL) amIAnIPad {
#if (__IPHONE_OS_VERSION_MAX_ALLOWED >= 30200)
if ([[UIDevice currentDevice] respondsToSelector: @selector(userInterfaceIdiom)])
return ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad);
#endif
return NO;
}
This conditionally compiles, so you can still build for the 3.0 sim. It then checks to see if the UIDevice class responds to the selector. If either of these fail, it's not an iPad.