Search code examples
objective-cios6ios-simulator

Checking device version during compilation (macro)


I know this topic might be a very commonly asked question but I still couldn't get the solution.

Firstly, I know there are two methods to check OS version

1)

[[UIDevice currentDevice] systemVersion]

This is definitely not something I'm looking for because this is used during runtime, what I'm looking at is something can be done during compilation.

2)

#if __IPHONE_6_0
// do something
#endif

This is something that I was hoping it to work but it doesn't. 2 problems here:

i) Running on iPhone simulator version 5.0 and I noticed #if __IPHONE_6_0 is returning TRUE value. I thought it suppose to be TRUE only if the version is 6.0 or above?

ii) Same thing happen when I tested it on iPad simulator. Does that macro works on iPad as well?

The reason that I want it to be done during compilation is because I'm using the latest iOS 6.0 Social Framework but I would like my app to support on older version (min 4.3) as well. Problem is part of my codes are using Social Framework stuffs. So I have to do a macro check to know whether this device support Social Framework or not, if not don't compile that particular Social Framework's codes. If I don't do that, I will be getting error during compilation because OS that below version 6 does not know what is Social Framework.

Looking forward to get some solutions here.


Solution

  • You can't use macros for this purpose because when you compile macros use YOUR version and it will not work for other devices(it seems to be obvious...)