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

  NSString *str;

  if( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad )
    str = [NSString stringWithString:@"Running as an iPad application"];
    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];


  [super viewDidLoad];