【发布时间】:2010-10-19 15:23:57
【问题描述】:
在我的通用应用程序中,我需要检查当前设备是 iPad 还是 iPhone。我怎样才能以编程方式做到这一点?我打算把代码放在我的 viewDidLoad 中。
【问题讨论】:
标签: iphone objective-c xcode ipad ios
在我的通用应用程序中,我需要检查当前设备是 iPad 还是 iPhone。我怎样才能以编程方式做到这一点?我打算把代码放在我的 viewDidLoad 中。
【问题讨论】:
标签: iphone objective-c xcode ipad ios
检查UISplitViewController 类在平台上是否可用,如果是,请确保它是使用 Apple 宏的 iPad(注意 UIUserInterfaceIdiomPad 常量仅在 iOS 3.2 及更高版本上可用)。
if (NSClassFromString(@"UISplitViewController") != nil && UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
//currentDeviceType = iPad;
}
else {
//currentDeviceType = iPhone;
}
【讨论】:
UIUserInterfaceIdiomPad 这样的常量的可用性是在编译时确定的,而不是在运行时确定的。 (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 在 3.2 之前的 iOS 版本上仍然可以正常工作。
我在所有应用中都使用了这个简单的功能:
#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
}
【讨论】: