简体   繁体   English

如何确定当前设备是iPhone还是iPad?

[英]How do I determine whether the current device is an iPhone or iPad?

In my universal app I need to check if the current device is an iPad or iPhone. 在我的通用应用程序中,我需要检查当前设备是iPad还是iPhone。 How can I do this programmatically? 我该如何以编程方式执行此操作? I plan to put the code in my viewDidLoad. 我打算把代码放在我的viewDidLoad中。

check if UISplitViewController class available on the platform, if so make sure it is iPad using Apple's macro (notice that UIUserInterfaceIdiomPad constant is available only on iOS 3.2 and up). 检查平台上是否有UISplitViewController类可用,如果是,请确保它是使用Apple宏的iPad(注意UIUserInterfaceIdiomPad常量仅在iOS 3.2及更高版本上可用)。

if (NSClassFromString(@"UISplitViewController") != nil && UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
        //currentDeviceType = iPad;
    }
    else {
        //currentDeviceType = iPhone;
    }

I use this simple function in all my apps: 我在所有应用中使用这个简单的功能:

#import "isPad.h"
BOOL isPad () {
    static BOOL isPad;
    static BOOL used = NO;  
    if (used)
        return isPad;
    used = YES;
    NSRange range = [[[UIDevice currentDevice] model] rangeOfString:@"iPad"];
    isPad = range.location != NSNotFound;
    return isPad;
}
try this.. this will help you.   

 NSString *deviceType = [UIDevice currentDevice].model;


        if([deviceType isEqualToString:@"iPod touch"]||[deviceType isEqualToString:@"iPhone"]||[deviceType isEqualToString:@"iPad"]){
        }
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
    // Statements
}

else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
   // Statements
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何确定当前连接的wifi在iPhone或iPad中是否安全 - How do I determine whether curreltly connected wifi is secure or not in iPhone or iPad 如何判断当前的iPhone/device model? - How to determine the current iPhone/device model? 如何判断设备(iPhone、iTouch 或 iPad)上是否有麦克风可用? - How can I tell whether a microphone is available on the device (iPhone, iTouch or iPad)? 如何使用iPhone / iPad SDK快速确定文件是否为图像文件 - How to quickly determine whether a file is an image file using iPhone/iPad SDK 如何以编程方式确定我的应用程序是iPad还是iPhone - How can I programmatically determine if my app iPad or iPhone 如何检查用户代理是 ipad 还是 iphone? - How do I check if the useragent is an ipad or iphone? iPhone和Ipad - 我如何分叉代码? - iPhone & Ipad - how do I fork a code? 如何检测iPhone 6设备的运动? (确定iPhone设备是否移动-在x,y,z-上的最小可能运动) - how to detect motion of iPhone 6 device? (determine whether iPhone device moved or not -smallest possible motion on x,y,z- ) 如何查询iPhone / iPad屏幕的当前方向? - How can I query the current orientation of an iPhone/iPad screen? 如何确定iphone / ipad / ipod / appletv是否较旧,较新或等同于同一家族的其他设备? - How to determine if iphone / ipad / ipod / appletv is older, newer or equal to other device of same family?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM