2010-09-24 48 views

回答

2

在我看来,这个问题是重复的,但我会尽量简要介绍我所知道的关于设备类型和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 
+1

'NSStrung' - 当您的字符串过期时。 ; P – deceze 2010-09-24 06:16:18

+0

哦,对不起,我已经输入了内容,没有拷贝。已更正:) – knuku 2010-09-24 06:19:19

+1

COMPILER检查在RUNTIME如何帮助您? – 2010-09-24 06:21:07

相关问题