1. 程式人生 > >[iOS] How to programmatically check if running on an iPhone or iPad device

[iOS] How to programmatically check if running on an iPhone or iPad device

In Swift:

if UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiom.Pad {

In Objective-C:

if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)

To check if you are running on an iPhone:

In Swift:

if UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiom.Phone {

In Objective-C:

if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)