为 iPad 进行编译时是否设置了特定的 Xcode 编译器标志?
为 iPad 进行编译时是否设置了特定的 Xcode 编译器标志?
我想有条件地编译 iPad 与 iPhone/iPod Touch 代码,例如:
#ifdef TARGET_IPAD
code for iPad
#else
code for iPhone
#endif
我知道 TargetConditionals.h 中已经有 TARGET_OS_IPHONE 和 TARGET_CPU_ARM,但是有什么可以轻松且专门针对 iPad 的吗?
-丽
Is there a specific Xcode compiler flag that gets set when compiling for iPad?
I want to conditionally compile iPad vs iPhone/iPod Touch code for example:
#ifdef TARGET_IPAD
code for iPad
#else
code for iPhone
#endif
I know there is already TARGET_OS_IPHONE and TARGET_CPU_ARM in TargetConditionals.h but anything that easily and specifically targets iPad?
-Rei
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
用于运行时检查 iPad 与 iPhone/iPad Touch 的正确 API 是:
UIDevice 头文件管理器还包含一个方便的宏 UI_USER_INTERFACE_IDIOM(),如果您的部署目标 <<,这将很有帮助。 iPhone 3.2。
所以你可以消极地说:
The correct API to use for run-time checking of iPad vs. iPhone/iPad Touch is:
The UIDevice header filer also includes a convenient macro, UI_USER_INTERFACE_IDIOM(), which will be helpful if your deployment target is < iPhone 3.2.
So you could just say, negatively:
您应该使用运行时检查,而不是使用编译时标志,例如使用 NSClassFromString 来查看类是否存在,因为相同的应用程序可以安装在两个设备上。
由于可能在两种设备上运行该应用程序,因此没有内置的编译时检查它是否针对 iPad。
Instead of using compile-time flags, you should use run-time check e.g. use
NSClassFromString
to see if a class exists because the same app can be installed on both devices.And because of the possibility of running the app in both devices, there isn't a built-in compile-time check whether it targets iPad or not.
目前我没有找到任何可以让你检查你是否使用 iPad 的东西,但我也不确定 Apple 是否建议运行时检查。以下是苹果公司的摘录:
但是,我没有地方可以找到有关条件编译宏的更多具体信息。
Currently I didn’t find anything that would let you check if you are on an iPad, but I’m also not sure if Apple recommends runtime checks. Here’s an excerpt from Apple:
However, there is no place I could find more specific information about conditional compilation macros.
对于共享相同项目/代码的多个目标,我通过编辑 iPad 目标的 C 标志来实现此目的。
选择 [myapp]-iPad 目标作为活动目标后,选择 Project ->编辑活动目标 [myapp]-iPad。搜索“c flags”并双击。添加“-D TARGET_IPAD”标志。现在,符号 TARGET_IPAD 将仅为您的 iPad 目标定义。
当然,这仅在您为 iPad 和 iPhone 使用单独的目标时才有效。如果您在两者上运行相同的二进制文件,显然编译器无法为您做任何事情。 (但是,截至一月底的 3.2 SDK 甚至还不支持通用应用程序。)
(已编辑;我对“通用”应用程序等术语感到困惑)
For multiple targets sharing the same project/code, I'm doing this by editing the C flags for my iPad target.
With the [myapp]-iPad target chosen as the active target, pick Project -> Edit Active Target [myapp]-iPad. Search for "c flags" and double-click. Add a flag for "-D TARGET_IPAD". Now the symbol TARGET_IPAD will be defined only for your iPad target.
Of course, this only works if you're using separate targets for iPad and iPhone. If you're running the same binary on both, obviously there's nothing the compiler can do for you. (However, the 3.2 SDK as of the end of January doesn't even support Universal apps yet.)
(Edited; I was confused about the terminology of "Universal" apps etc.)
或者->只是为了确定
Or -> just to be sure
我想这会做
I think this will do