如何检查 iOS 版本是 iOS 6?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12561599/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to check iOS Version is iOS 6?
提问by Fire Fist
Possible Duplicate:
Check iPhone iOS Version
可能重复:
检查 iPhone iOS 版本
I want to check iOS Version in iOS.
我想在 iOS 中检查 iOS 版本。
Because i have some of codes only for iOS 6.
因为我有一些仅适用于 iOS 6 的代码。
So how can i?
那我怎么办?
回答by Fábio Oliveira
Check this GitHub Gist https://gist.github.com/998472
检查此 GitHub 要点 https://gist.github.com/998472
You can add the code or include it in your ...-Prefix.pch file so you can use it wherever you need it.
您可以添加代码或将其包含在您的 ...-Prefix.pch 文件中,以便您可以在任何需要的地方使用它。
EDIT
编辑
I'm leaving an example of how you can use the code from Gist so people can check if it's useful for their case. This can also be found over the Gist.
我将留下一个示例,说明如何使用 Gist 中的代码,以便人们可以检查它是否对他们的案例有用。这也可以在 Gist 上找到。
/*
* Usage
*/
if (SYSTEM_VERSION_LESS_THAN(@"4.0")) {
...
}
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"3.1.1")) {
...
}
回答by Lorenz Lo Sauer
Try this:
尝试这个:
Update:
更新:
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..
}
Previous code:
以前的代码:
NSArray *vComp = [[UIDevice currentDevice].systemVersion componentsSeparatedByString:@"."];
if ([[vComp objectAtIndex:0] intValue] == 6) {
// iOS-6 code
} else {
// iOS-5, iOS-4... code
}
To specifically check for a subversion of IOS use
专门检查IOS使用的颠覆
float sysVer = [[[UIDevice currentDevice] systemVersion] floatValue];
if (sysVer > 6.01) {
// iOS-6.01+ code
} else {
// prior iOS versions
}
回答by dsgriffin
You can get the iOS version as a string using:
您可以使用以下方法将 iOS 版本作为字符串获取:
[[UIDevice currentDevice] systemVersion]