简体   繁体   English

是以编程方式设备iPhone或iPad

[英]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.

相关问题 如果(设备 == iPad),如果(设备 == iPhone) - if (device == iPad), if (device == iPhone) 如何以编程方式获取设备(iPhone / iPad / AppleTV等)的唯一ID? - How to get an unique id for a device (iPhone/iPad/AppleTV, etc) programmatically? 如何以编程方式检查 iPhone/iPad 设备是否有原深感摄像头? - How to programmatically check if the iPhone/iPad device has a TrueDepth Camera? 以编程方式锁定iPhone和iPad屏幕 - Lock iPhone and iPad Screen programmatically 以编程方式获取iPad设备信息 - Grabbing iPad device information programmatically 以编程方式识别iphone设备 - programmatically identifing the iphone device 如何以编程方式更改iphone和ipad设备设置->电子邮件地址和名称? - How can I change the iphone and ipad device settings -> email address and name programmatically? 在应用程序处于特定状态时以编程方式限制用户对Android / iPad / iPhone设备的访问 - Programmatically restrict user access to Android/iPad/iPhone device while an app is in a certain state 根据设备(iPhone或iPad)的不同设备方向 - Different Device Orientation according to device (iPhone or iPad) 如何使用IOS(iPhone,iPad)以编程方式下载文件? - How to programmatically download a file with IOS (iPhone, iPad)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM