2010-09-24 30 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

相關問題