我需要重新配置基於我運行的iOS版本的一些用戶界面,所以我需要一個檢查iOS版本的好方法。目前我這樣做:檢查iOS 7或更低版本的最佳方法?
if ([[[UIDevice currentDevice] systemVersion] isEqualToString: @"7.0"]) {
//do stuff
}
我寧願不硬編碼這些字符串比較,並根據它作出決定。有沒有更好的方法來做到這一點?
我需要重新配置基於我運行的iOS版本的一些用戶界面,所以我需要一個檢查iOS版本的好方法。目前我這樣做:檢查iOS 7或更低版本的最佳方法?
if ([[[UIDevice currentDevice] systemVersion] isEqualToString: @"7.0"]) {
//do stuff
}
我寧願不硬編碼這些字符串比較,並根據它作出決定。有沒有更好的方法來做到這一點?
我總是把那些在我Constants.h文件:
#define IS_IPHONE5 (([[UIScreen mainScreen] bounds].size.height-568)?NO:YES)
#define IS_OS_5_OR_LATER ([[[UIDevice currentDevice] systemVersion] floatValue] >= 5.0)
#define IS_OS_6_OR_LATER ([[[UIDevice currentDevice] systemVersion] floatValue] >= 6.0)
#define IS_OS_7_OR_LATER ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)
#define IS_OS_8_OR_LATER ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
#define IS_OS_9_OR_LATER ([[[UIDevice currentDevice] systemVersion] floatValue] >= 9.0)
雖然我總是喜歡上面的宏,爲接受的答案的完成,這裏是蘋果的批准方式:
if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_6_1) {
// do stuff for iOS 7 and newer
}
else {
// do stuff for older versions than iOS 7
}
if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_6_1) {
// do stuff for iOS 7 and newer
}
else {
// do stuff for older versions than iOS 7
}
+1我以前從未見過這個。 –
對於它的價值,這是蘋果在採用iOS 7會議的2013 Tech Talk上的建議 - 儘管他們在調用「floor()」時包裝了「NSFoundationVersionNumber」。 –
會不會有一個6.2.x會使檢查無效? –
如果iOS 7.1出來的話,將會中斷。但是你在正確的軌道上。如果你關心的是iOS7,一般來說,將字符串分開並僅比較主要版本。 – Krumelur
有你看着[1] [1] [這個答案?]:http://stackoverflow.com/questions/12561599/how-to-check-ios-version-is-ios-6/12561661#12561661 – shrimp
這看起來最穩定 – Huang