How to determine iPhone OS version using macros

I would like to know the version of iPhone OS in my application. I tried using the discovery code, but I was recommended to use macros. Does anyone have any experience, can you post a sample code and which library to use.

+2
iphone
source share
2 answers

I’m not sure which macros you were advised to use. I always thought that the standard way to find the version number, so that it was compatible with future and previous versions, was to use

NSString* versionNumber = [[UIDevice currentDevice] systemVersion] 

which gives it as an NSString such as @ "2.0" or @ "2.2.1"

There are version constants that describe the version of Foundation classes used, with NSFoundationVersionNumber , but I'm not sure how reliable this will be in older and future code.

+6
source share

Have a look at Availability.h, in particular, for statements:

 #define __IPHONE_2_0 20000 #define __IPHONE_2_1 20100 #define __IPHONE_2_2 20200 #define __IPHONE_3_0 30000 #define __IPHONE_NA 99999 

And don't forget to read the comment of the giant headline. Preprocessor macros are by far the safest way to split your code into an os version.

+5
source share

All Articles