Reputation: 781
I am developing global application (iPhone and iPad). I am doing different process for iPhone or iPad. But I saw crash like below screen shot. This crash device is iPhone but have run the code I wrote for iPad. How could this be. I wrote code that distinguishes the iPhone and iPad is faulty? thanx
-(IBAction)showSearchAirports:(id)sender{
UIButton *tempButton=(UIButton*)sender;
AirportSearch2 *airportsSearch=[[AirportSearch2 alloc] initWithNibName:@"AirportSearch" bundle:nil];
if ([self isDeviceiPhone]) {
[self presentViewController:airportsSearch animated:YES completion:NULL];
}else{
if (self.popOver) {
[self.popOver dismissPopoverAnimated:YES];
self.popOver = nil;
}
UINavigationController *navigationController = [[[UINavigationController alloc] initWithRootViewController:airportsSearch] autorelease];
self.popOver=[[[UIPopoverController alloc] initWithContentViewController:navigationController] autorelease];
self.popOver.delegate = self;
[self.popOver setPopoverContentSize:CGSizeMake(285, 370)];
//This line 481
[self.popOver presentPopoverFromRect:tempButton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionRight animated:YES];
}
}
-(BOOL)isDeviceiPhone{
if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
return TRUE;
else
return FALSE;
}
Upvotes: 1
Views: 2582
Reputation: 12023
try this
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
// The device is an iPad running iOS 3.2 or later.
Return NO;
}
else
{
// The device is an iPhone or iPod touch.
Return YES;
}
Upvotes: 4
Reputation: 1155
You haven't shown us the code you use to determine the type of device, but here's one way you can determine device type at runtime.
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
// iPad-specific interface here
}
else
{
// iPhone and iPod touch interface here
}
Upvotes: 0
Reputation: 1087
just use this Macro Defined in UIdevice Class you can refer to documentation (https://developer.apple.com/LIBRARY/IOS/documentation/UIKit/Reference/UIDevice_Class/Reference/UIDevice.html) also just simply use condition like
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
return yes;
}
else
return No;
Upvotes: 0
Reputation: 5064
To detect device type use following methods :
+ (BOOL) isiPad {
#if (__IPHONE_OS_VERSION_MAX_ALLOWED >= 30200)
if ([[UIDevice currentDevice] respondsToSelector: @selector(userInterfaceIdiom)])
return ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad);
#endif
return NO;
}
+(BOOL)isiPhone
{
NSString *deviceType = [UIDevice currentDevice].model;
if([deviceType isEqualToString:@"iPhone"])
return YES;
else
return NO;
}
Upvotes: 0