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?
那我该怎么办?
3 个解决方案
#1
49
Check this GitHub Gist https://gist.github.com/998472
检查这个GitHub Gist 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")) {
...
}
#2
40
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
}
#3
12
You can get the iOS version as a string using:
您可以使用以下方式将iOS版本作为字符串获取:
[[UIDevice currentDevice] systemVersion]
#1
49
Check this GitHub Gist https://gist.github.com/998472
检查这个GitHub Gist 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")) {
...
}
#2
40
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
}
#3
12
You can get the iOS version as a string using:
您可以使用以下方式将iOS版本作为字符串获取:
[[UIDevice currentDevice] systemVersion]