Categories
Code Snippets

Detect iPhone or iPad

To determine whether your application is running on an iPhone, iPod Touch or iPad you can simply include the following code and you can re-purpose your User Interface accordingly.


- (void)viewDidLoad
{
#if (__IPHONE_OS_VERSION_MAX_ALLOWED >= 30200 )

  NSString *str;

  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];

#endif

  [super viewDidLoad];
}