sid
sid

Reputation: 115

How to detect iPhone OS version using macros

I would like to detect iPhone OS version in my app. I have tried using detection code but was advised to use macros. Does someone experience, can you post sample code, and what library to use.

Upvotes: 2

Views: 4003

Answers (2)

Cajunluke
Cajunluke

Reputation: 3113

Look in Availability.h, specifically the 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 giant header comment. The preprocessor macros are definitely the safest way to section out your code by os version.

Upvotes: 5

user120587
user120587

Reputation:

I am not certain what macros you are being advised to use. I always thought that the standard way to find the version number so that it will be compatiable with future and previous versions was to use

NSString* versionNumber = [[UIDevice currentDevice] systemVersion]

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

There are the Version constants that describe the version of Foundation classes being used, with NSFoundationVersionNumber but I am uncertain of how reliable this will be in older and future code.

Upvotes: 6

Related Questions