Is it possible to check UI_USER_INTERFACE_IDIOM () to determine if it is an iPhone or iPad?

I found this code here :

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { str = [NSString stringWithString:@"Running as an iPad application"]; } else { str = [NSString stringWithString: @"Running as an iPhone/iPod touch application"]; } UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Platform" message:str delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; [alert release]; 

How safe is this check? Does Apple really recommend doing this? Or it may happen that he does not detect an iPad as an iPad or an iPhone as an iPhone?

+4
source share
1 answer

It should be safe enough, this is well documented by Apple.

This is just a shorthand for the following code:

 if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) { // etc 

Perhaps this may happen with an error if you try to run it on something smaller than iOS 3.2 (as it was introduced then), but it may not be a problem for you.

+7
source

All Articles