7

I use this code

#define IS_IOS7 (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_6_1)

To find if the app is running on iOS7. But I now need to know if it runs on iOS7.1 but there isn't any NSFoundationVersionNumber_iOS_7_0 and NSFoundationVersionNumber_iOS_7_1

I know the definition of

#define NSFoundationVersionNumber_iOS_6_1  993.00

So maybe I can compare with a number higher than 993 but I don't know. Someone gets a safe and reliable solution ?

tshepang
  • 12,111
  • 21
  • 91
  • 136
Tancrede Chazallet
  • 7,035
  • 6
  • 41
  • 62

3 Answers3

9

There are several ways to do this, and you can easily find them in several answers here on SO. Here are some:

[[UIDevice currentDevice] systemVersion]

Slightly more complex, with test:

if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1) {
    // iOS7...
}

You can add a more complete way to test for version like this:

/*
 *  System Versioning Preprocessor Macros
 */ 

#define SYSTEM_VERSION_EQUAL_TO(v)                  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define SYSTEM_VERSION_GREATER_THAN(v)              ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN(v)                 ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v)     ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)

/*
 *  Usage
 */ 

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

if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"3.1.1")) {
    ...
}

Sources:

How to check iOS version?

How can we programmatically detect which iOS version is device running on?

Community
  • 1
  • 1
Marius Waldal
  • 9,537
  • 4
  • 30
  • 44
2

Try below code

 float fOSVersion=[[[UIDevice currentDevice] systemVersion] floatValue];
     if(fOSVersion>7.0)//if it is greater than 7.0
     {
          //do your stuff here          
     }
svrushal
  • 1,612
  • 14
  • 25
1

Define this marco

#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)

And you can check version like this

if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.1")){
   //do something
}
MineS Chan
  • 29
  • 2