// Do not worry the iPhone simulator 3.2+ will get you the iPad simulator,
// or compile for iPhone Device 3.2 or 4.0 and put the app on a phone to test it.
// iPhone 4 has different screen size so do not forget to check the iPhone hardware too
#if (__IPHONE_OS_VERSION_MAX_ALLOWED >= 30200)
NSString *str;
// Note that UI_USER_INTERFACE_IDIOM() and UIUserInterfaceIdiomPad are NOT defined in the SDKs prior to 3.2.
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
// The device is an iPad
// For example load appropriate iPad nib file
str = [NSString stringWithString:@"We are running an iPad application"];
} else {
// The device is an iPhone or iPod touch, but check for screen sizes!
// For example load your iPhone nib file
str = [NSString stringWithString: @"We are running an iPhone/iPod Touch application"];
}
// Let's see what we have found
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Platform check"
message:str
delegate:nil
cancelButtonTitle:@"Done"
otherButtonTitles:nil];
[alert show];
[alert release];
#endif
// Another bullet proof solution:
- (BOOL) isiPad {
#if (__IPHONE_OS_VERSION_MAX_ALLOWED >= 30200)
if ([[UIDevice currentDevice] respondsToSelector: @selector(userInterfaceIdiom)])
return ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad);
#endif
return NO;
}
// or compile for iPhone Device 3.2 or 4.0 and put the app on a phone to test it.
// iPhone 4 has different screen size so do not forget to check the iPhone hardware too
#if (__IPHONE_OS_VERSION_MAX_ALLOWED >= 30200)
NSString *str;
// Note that UI_USER_INTERFACE_IDIOM() and UIUserInterfaceIdiomPad are NOT defined in the SDKs prior to 3.2.
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
// The device is an iPad
// For example load appropriate iPad nib file
str = [NSString stringWithString:@"We are running an iPad application"];
} else {
// The device is an iPhone or iPod touch, but check for screen sizes!
// For example load your iPhone nib file
str = [NSString stringWithString: @"We are running an iPhone/iPod Touch application"];
}
// Let's see what we have found
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Platform check"
message:str
delegate:nil
cancelButtonTitle:@"Done"
otherButtonTitles:nil];
[alert show];
[alert release];
#endif
// Another bullet proof solution:
- (BOOL) isiPad {
#if (__IPHONE_OS_VERSION_MAX_ALLOWED >= 30200)
if ([[UIDevice currentDevice] respondsToSelector: @selector(userInterfaceIdiom)])
return ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad);
#endif
return NO;
}
// Separate XIB files represent the UI for each device
NSArray *nibViews = nil;
// Read MyOwnView.xib or MyOwnView-iPad.xib
NSString *nameNib = [self isiPad] ? @"MyOwnView-iPad" : @"MyOwnView";
nibViews = [[NSBundle mainBundle] loadNibNamed: nameNib owner:self options:nil];
self.myActualView = nil;
if( nibViews!=nil && [nibViews count] > 0 ){
self.myActualView = (UIView *)[nibViews objectAtIndex: 0];
// You have read the view from the proper XIB
}
NSArray *nibViews = nil;
// Read MyOwnView.xib or MyOwnView-iPad.xib
NSString *nameNib = [self isiPad] ? @"MyOwnView-iPad" : @"MyOwnView";
nibViews = [[NSBundle mainBundle] loadNibNamed: nameNib owner:self options:nil];
self.myActualView = nil;
if( nibViews!=nil && [nibViews count] > 0 ){
self.myActualView = (UIView *)[nibViews objectAtIndex: 0];
// You have read the view from the proper XIB
}
width = s.width;
height = s.height;