开发者

What is the difference between #ifdef __IPHONE_3.2 and #if __IPHONE_3.2?

I have an iphone app that needs to work for 3.1.3 for the iPhone and 3.2 for the iPad. It is an iPhone app that I want to work on the iPad.

The main difference is the MPMoviePlayerController which introduces/and deprecates lots of things in 3.2.

Since, the iPhone OS only goes up to 3.1.3 and the iPad is on 3.2, I need to seperate my code so it only compiles the required code for the respective OS.

I can't use [[UIDevice currentDevice] model] because I end up with deprecated warnings on the 3.1.3 code. Also, UIUserInterfaceIdiomPad is new in 3.2 so it doesn't work well with 3.1.3...

So, I deci开发者_运维技巧ded to use this, which only compiles what is necessary for the particular OS:

#if __IPHONE _3_2

//do 3.2 iPad stuff

#else

//do 3.1.3 iPhone/iPod Touch stuff

#endif

My question is... What is the difference between these?

#ifdef __IPHONE_3_2

and

#if __IPHONE_3_2

Thank you


Strictly speaking, #ifdef will see if __IPHONE_3_2 has been given any value while #if __IPHONE_3_2 will check for specific values.

In this case, I would use #ifdef __IPHONE_3_2 because you only need to check to see if the value exists.

(FYI, __IPHONE_3_2 is defined to be the value 30200 in case you were curious.)


You can't use checks at compile-time to check things that are runtime-related. You should use -respondsToSelector: or the UIInterfaceIdiom() macro.

Make sure to link against the 3.2 SDK (which means to set the Base SDK to 3.2) and set your Deployment Target to the lowest iPhone OS version you want to support (3.1.3 it seems).

Have a look at this: Introducing Universal Applications for iPhone OS.


Testing for __IPHONE_3_2 is the only way to compile code on 3.1 that has 3.2 symbols , you are missing the point entirely recommending NSClassFromString()/respondsToSelector:/UIInterfaceIdiom(), those can not be used in header definitions for example, nor do they solve the linking errors, they are the solution to a totally different problem.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜