Check iOS version at runtime?

to conform to version specified in system defines

//#define __IPHONE_2_0 20000
//#define __IPHONE_2_1 20100
//#define __IPHONE_2_2 20200
//#define __IPHONE_3_0 30000
//#define __IPHONE_3_1 30100
//#define __IPHONE_3_2 30200
//#define __IPHONE_4_0 40000
You can write function like this ( you should probably store this version somewhere rather than calculate it each time ):

+ (NSInteger) getSystemVersionAsAnInteger{
    int index = 0;
    NSInteger version = 0;

    NSArray* digits = [[UIDevice currentDevice].systemVersion componentsSeparatedByString:@"."];
    NSEnumerator* enumer = [digits objectEnumerator];
    NSString* number;
    while (number = [enumer nextObject]) {
        if (index>2) {
            break;
        }
        NSInteger multipler = powf(100, 2-index);
        version += [number intValue]*multipler;
        index++;
    }
return version;
}

Then you can use this as follows:

if([Toolbox getSystemVersionAsAnInteger] >= __IPHONE_4_0)
{
  //blocks
} else 
{
  //oldstyle
}

Simpler solution for anyone who'll need help in the future:

NSArray *versionCompatibility = [[UIDevice currentDevice].systemVersion componentsSeparatedByString:@"."];

if ( 5 == [[versionCompatibility objectAtIndex:0] intValue] ) { /// iOS5 is installed

    // Put iOS-5 code here

} else { /// iOS4 is installed

    // Put iOS-4 code here         

}

In many cases you do not need to check iOS version directly, instead of that you can check whether particular method is present in runtime or not.

In your case you can do the following:

if ([[UIView class] respondsToSelector:@selector(animateWithDuration:animations:)]){
// animate using blocks
}
else {
// animate the "old way"
}

Xcode 7 added the available syntax making this relatively more simple:

Swift:

if #available(iOS 9, *) {
    // iOS 9 only code
} 
else {
   // Fallback on earlier versions
}

Xcode 9 also added this syntax to Objective-C

Objective-C:

if (@available(iOS 9.0, *)) {
   // iOS 9 only code
} else {
   // Fallback on earlier versions
}