我需要根据要运行的iOS版本重新配置一些UI,因此需要一种检查iOS版本的好方法。目前我正在这样做:
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
}
本文地址:http://ios.askforanswer.com/jianchaios-7huogengzaobanbendezuijiafangfazhongfu.html
文章标签:ios , ios6 , ios7
版权声明:本文为原创文章,版权归 admin 所有,欢迎分享本文,转载请保留出处!
文章标签:ios , ios6 , ios7
版权声明:本文为原创文章,版权归 admin 所有,欢迎分享本文,转载请保留出处!
评论已关闭!