#ifdef __IPHONE_3.2和#if __IPHONE_3.2有什么区别?

时间:2021-12-13 20:53:30

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.

我有一个iPhone应用,需要适用于iPhone 3.1.3和iPad 3.2。这是一款我想在iPad上运行的iPhone应用程序。

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

主要的区别是MPMoviePlayerController引入/并弃用了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.

因为,iPhone OS仅上升到3.1.3而iPad在3.2上,我需要分离我的代码,因此它只编译相应操作系统所需的代码。

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

我不能使用[[UIDevice currentDevice] model]因为我最终在3.1.3代码上发布了弃用的警告。此外,UIUserInterfaceIdiomPad是3.2中的新功能,因此它不适用于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

3 个解决方案

#1


3  

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

严格地说,#ifdef将查看__IPHONE_3_2是否已被赋予任何值,而#if __IPHONE_3_2将检查特定值。

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

在这种情况下,我会使用#ifdef __IPHONE_3_2,因为您只需要检查该值是否存在。

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

(仅供参考,__ IPHONE_3_2定义为值30200,以防您感到好奇。)

#2


3  

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

您无法在编译时使用检查来检查与运行时相关的内容。您应该使用-respondsToSelector:或UIInterfaceIdiom()宏。

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

确保链接3.2 SDK(这意味着将Base SDK设置为3.2)并将您的部署目标设置为您想要支持的最低iPhone OS版本(3.1.3)。

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

看看这个:为iPhone OS推出通用应用程序。

#3


0  

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.

测试__IPHONE_3_2是编译具有3.2个符号的3.1上的代码的唯一方法,您缺少完全推荐NSClassFromString()/ respondsToSelector:/ UIInterfaceIdiom()的点,例如,那些不能在头定义中使用,也不能解决链接错误,它们是一个完全不同的问题的解决方案。

#1


3  

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

严格地说,#ifdef将查看__IPHONE_3_2是否已被赋予任何值,而#if __IPHONE_3_2将检查特定值。

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

在这种情况下,我会使用#ifdef __IPHONE_3_2,因为您只需要检查该值是否存在。

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

(仅供参考,__ IPHONE_3_2定义为值30200,以防您感到好奇。)

#2


3  

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

您无法在编译时使用检查来检查与运行时相关的内容。您应该使用-respondsToSelector:或UIInterfaceIdiom()宏。

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

确保链接3.2 SDK(这意味着将Base SDK设置为3.2)并将您的部署目标设置为您想要支持的最低iPhone OS版本(3.1.3)。

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

看看这个:为iPhone OS推出通用应用程序。

#3


0  

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.

测试__IPHONE_3_2是编译具有3.2个符号的3.1上的代码的唯一方法,您缺少完全推荐NSClassFromString()/ respondsToSelector:/ UIInterfaceIdiom()的点,例如,那些不能在头定义中使用,也不能解决链接错误,它们是一个完全不同的问题的解决方案。