Detects iOS Version 7.1

I am using this code

#define IS_IOS7 (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_6_1) 

To find out if the application works on iOS7. But now I need to know if it works on iOS7.1, but there is no NSFoundationVersionNumber_iOS_7_0 and NSFoundationVersionNumber_iOS_7_1

I know the definition

 #define NSFoundationVersionNumber_iOS_6_1 993.00 

So maybe I can compare with a number above 993, but I don’t know. Does anyone get a safe and reliable solution?

+7
ios ios7
source share
3 answers

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

 [[UIDevice currentDevice] systemVersion] 

A bit trickier with the test:

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

You can add a more complete testing method for the version as follows:

 /* * 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 determine which version of iOS the device is running on?

+9
source share

Try entering the code

  float fOSVersion=[[[UIDevice currentDevice] systemVersion] floatValue]; if(fOSVersion>7.0)//if it is greater than 7.0 { //do your stuff here } 
+2
source share

Define it marco

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

And you can check a version like this

 if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.1")){ //do something } 
+1
source share

All Articles