可能重复:
Best way to programmatically detect iPad/iPhone hardware如何以编程方式区分iPad和iPhone?
我如何区分iPad和iPhone编程?
可能重复:
Best way to programmatically detect iPad/iPhone hardware如何以编程方式区分iPad和iPhone?
我如何区分iPad和iPhone编程?
在我看来,这个问题是重复的,但我会尽量简要介绍我所知道的关于设备类型和iOS版本检测的所有信息。
根据您想要接收的信息,无论是设备类型(iPhone,iPod或iPad)还是iOS版本,都有几种方法。
在这里被用于检测设备类型码(返回在模拟器的情况下I386):
#import <sys/utsname.h>
+ (NSString *)getDeviceType {
struct utsname systemInfo;
return [NSString stringWithCString:systemInfo.machine encoding:NSUTF8Encoding];
}
这里是IOS版本检测器:
+ (float)getOSVersion {
return [[[UIDevice currentDevice] systemVersion] floatValue];
}
而用于编译器的OS检测器:
#ifdef __IPHONE_4_0
//this part of code will be running on devices with os iOS4+
#else
//this part of code will be running on devices with os _UNDER_ iOS4+
#endif
此外,没有人proibits我们使用
#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED > 40000
//this part of code will be running on devices with os iOS4+
#endif
你什么意思,你需要在Objective-C开始iPhone编程? – 2010-09-24 05:24:23
@Micheal:我想他是指如何判断它是iPhone还是iPad。 – 2010-09-24 05:25:24
弹出一个对话框询问“这是iPhone还是iPad?”。这应该够了吧。 :D – 2010-09-24 06:19:12