26

Possible Duplicate:
Check iPhone iOS Version

I want to check iOS Version in iOS.

Because i have some of codes only for iOS 6.

So how can i?

Community
  • 1
  • 1
Fire Fist
  • 7,032
  • 12
  • 63
  • 109

3 Answers3

49

Check this 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.


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.

/*
 *  Usage
 */ 

if (SYSTEM_VERSION_LESS_THAN(@"4.0")) {
    ...
}

if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"3.1.1")) {
    ...
}
Fábio Oliveira
  • 2,346
  • 21
  • 30
  • While I love the code you have over in the gist (as I commented there), it'd be even better if you could include an example of it in this answer. – Will Moore Mar 22 '13 at 16:52
  • It's not my gist and I won't include the code here as the gist is made to be improved over time and this answer is stale in time. However I'm going to leave an example of how to use it so people can see if it's useful for their case. Thanks for caring :) – Fábio Oliveira Mar 22 '13 at 16:58
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

float sysVer = [[[UIDevice currentDevice] systemVersion] floatValue];

if (sysVer > 6.01) {
    // iOS-6.01+ code
} else {
    // prior iOS versions
}
Lorenz Lo Sauer
  • 23,698
  • 16
  • 85
  • 87
12

You can get the iOS version as a string using:

[[UIDevice currentDevice] systemVersion]
Nils Munch
  • 8,805
  • 11
  • 51
  • 103
dsgriffin
  • 66,495
  • 17
  • 137
  • 137