如何建立一个iPhone通用二进制当测试一个常量是否存在等 [英] How to test for the existance of a constant when creating a iPhone universal binary

查看:201
本文介绍了如何建立一个iPhone通用二进制当测试一个常量是否存在等的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个支持对iPhone 4的多任务处理通用二进制而且还可以在iPad上运行。

I am trying to create a universal binary that supports multitasking on the iPhone 4 and can still run on the iPad.

我知道如何避免通过检查,如果通过使用NSClassFromString和respondToSelector存在一类编译不同版本的iPhone IOS的​​错误,但有没有办法来检查常量是否存在类似UIBackgroundTaskInvalid?

I know how to avoid compile errors for different versions of the iPhone IOS by checking if a class exists by using NSClassFromString and "respondToSelector", but is there a way to check for the existence of constants like UIBackgroundTaskInvalid?

我当然可以用#IFDEF,但我想避免这种情况。

I of course can use #IFDEF, but I want to avoid this.

推荐答案

您做如下:

if (NULL != &UIBackgroundTaskInvalid) {
   //do multitasking stuff here
} else {
   // don't do multitasking stuff here.
}

基本上你要验证该变量的地址是否存在。

Basically you want to verify that the address of that variable exists.

更新:很明显,你不能真正用于此#ifdef来,因为你将与一个版本包含符号的SDK建立

Update: To be clear, you can't really use an #ifdef for this since you will build with a version of the SDK that contains the symbols.

这篇关于如何建立一个iPhone通用二进制当测试一个常量是否存在等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆