views:

861

answers:

3

Hi,

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 decided 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

+2  A: 

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.)

MrHen
I was hoping somebody would actually answer the question ;-)
Billy Gray
+3  A: 

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.

bddckr
Thank you ChriB, you are right. But if I set my target to 3.1.3, I get errors because the MPMoviePlayerController works differently in 3.2. If I set it to 3.2, then it wont work on iPhones (3.1.3). I am not actually trying to create a Universal app. Just tryingh to adjust my iPhone app to work on the iPad (as an iPhone app). But the MPMovieController won't allow me (or I can't figure it out).
Jonathan
As far as I know, every iPhone app runs natively on the iPad. You don't have to change anything for this. If you're trying to change something to run on the iPad - which means the app isn't running in the "iPhone mode" on the iPad - you **are** building an universal app. :P
bddckr
The majority of Apps do, They obviously did their best to keep it that way. But not every App does. The MPMoviePlayerController simply works differently in 3.2. They elude to it in the features page for the iPad on the Apple store.
Jonathan
A: 

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.

valexa
Well what is the problem then? As I understand it, he wants his code work on the iPhone which should also run on the iPad in "iPhone mode". This is nothing that has to do anything with 3.2. He should just code for iPhone OS which is 3.1.3 at the moment. This will let him code for the iPhone and let his app run as an iPhone app on the iPad. If he wants to code something differently for the iPad he will need to build an universal application.
bddckr