How to detect user is using iPad or iPhone for iOS App at run time conditional coding purposes

At runtime you want to detect user is on iPad or on iPhone for conditional coding purposes.

One of the need of doing it would be finding screen size of device with iPad or iPhone and iPod touch

Another need of doing it is to right different code i.e. conditional code per device i.e. whether it be iPad with big screen size or iPhone with smaller screen size or just to find out which storyboard you are writing code for.

Here is example,

Code is simple:


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

Hope it helps,

Thanks & Regards
Mandar Apte

Mandar Apte

This website contains a design articles blog by Mandar Apte. He writes and shares his iOS development, graphic, web, & animation film design experience through articles. Mandar is Mumbai based multi-disciplinary designer with expertise in UI, UX, Logo, Symbol, and Brand Identity design. He is an alumnus of Sir J. J. Institute of Applied Art, Mumbai. He currently runs his studio in the heart of the city of Mumbai.

Leave a Reply

Your email address will not be published. Required fields are marked *