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

时间:2010-10-19 15:23:58

标签: iphone objective-c xcode ipad ios

在我的通用应用程序中,我需要检查当前设备是iPad还是iPhone。我该如何以编程方式执行此操作?我打算把代码放在我的viewDidLoad中。

5 个答案:

答案 0 :(得分:9)

检查平台上是否有UISplitViewController类可用,如果是,请确保它是使用Apple宏的iPad(注意UIUserInterfaceIdiomPad常量仅适用于iOS 3.2及更高版本。)

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

答案 1 :(得分:1)

答案 2 :(得分:1)

我在所有应用中使用这个简单的功能:

#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;
}

答案 3 :(得分:1)

try this.. this will help you.   

 NSString *deviceType = [UIDevice currentDevice].model;


        if([deviceType isEqualToString:@"iPod touch"]||[deviceType isEqualToString:@"iPhone"]||[deviceType isEqualToString:@"iPad"]){
        }

答案 4 :(得分:0)

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
    // Statements
}

else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
   // Statements
}
相关问题