Best way to programmatically detect iPad/iPhone hardware

Checking at runtime (your first way) is completely different from #if at compile time. The preprocessor directives won’t give you a universal app.

The preferred way is to use Apple’s Macro:

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
     // The device is an iPad running iPhone 3.2 or later.
}
else
{
     // The device is an iPhone or iPod touch.
}

Use 3.2 as the base SDK (because the macro is not defined pre 3.2), you can target prior OS versions to get it running on the iPhone.

Leave a Comment