请查看这个GitHub Gist:https://gist.github.com/998472
你可以将该代码添加或包含在...-Prefix.pch文件中,以便在需要时随处使用。
编辑:
我留下了一个示例,展示如何使用Gist中的代码,这样人们就可以检查它是否对他们有用。 这也可以在Gist上找到。
/*
* Usage
*/
if (SYSTEM_VERSION_LESS_THAN(@"4.0")) {
...
}
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"3.1.1")) {
...
}
试试这个:
更新:
NSArray *vComp = [[UIDevice currentDevice].systemVersion componentsSeparatedByString:@"."];
if ([[vComp objectAtIndex:0] intValue] >= 7) {
// iOS-7 code[current] or greater
} else if ([[vComp objectAtIndex:0] intValue] == 6) {
// iOS-6 code
} else if ([[vComp objectAtIndex:0] intValue] > 2) {
// iOS-3,4,5 code
} else {
// iOS-1,2... code: incompatibility warnings, legacy-handlers, etc..
}
之前的代码:
NSArray *vComp = [[UIDevice currentDevice].systemVersion componentsSeparatedByString:@"."];
if ([[vComp objectAtIndex:0] intValue] == 6) {
// iOS-6 code
} else {
// iOS-5, iOS-4... code
}
要特别检查 IOS 的子版本,请使用
float sysVer = [[[UIDevice currentDevice] systemVersion] floatValue];
if (sysVer > 6.01) {
// iOS-6.01+ code
} else {
// prior iOS versions
}
if ([[vComp objectAtIndex:0] intValue] >= 6)
。 - colincameron您可以使用以下代码获取 iOS 版本号:
[[UIDevice currentDevice] systemVersion]