[英]is device iPhone or iPad programmatically
I am developing global application (iPhone and iPad). 我正在开发全球应用程序(iPhone和iPad)。 I am doing different process for iPhone or iPad.
我正在为iPhone或iPad做不同的处理。 But I saw crash like below screen shot.
但我看到像屏幕截图下面的崩溃。 This crash device is iPhone but have run the code I wrote for iPad.
这个崩溃设备是iPhone,但运行了我为iPad写的代码。 How could this be.
怎么可能。 I wrote code that distinguishes the iPhone and iPad is faulty?
我写的区别iPhone和iPad的代码有问题吗? 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;
}
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;
}
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;
}
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 只需在UI设备类中使用此宏定义,您可以参考文档( https://developer.apple.com/LIBRARY/IOS/documentation/UIKit/Reference/UIDevice_Class/Reference/UIDevice.html )也只是简单地使用条件
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
return yes;
}
else
return No;
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
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.