在运行时检测iPhone是否正在运行Debug/Distribution版本 [英] Detect if the iPhone is running a Debug/Distribution build at runtime

查看:72
本文介绍了在运行时检测iPhone是否正在运行Debug/Distribution版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在运行时检测正在运行的应用程序是否已通过调试或分发进行编译.

Is it possible at runtime to detect if the application that is running was compiled with debug or distribution.

推荐答案

在项目信息"中,对于Debug配置,添加"DEBUG"的预处理器宏(在GCC 4.2-预处理"部分中).

In the Project Info, for a Debug configuration, add a Preprocessor Macro of "DEBUG" (in the GCC 4.2 - Preprocessing section).

在代码中,您可以使用#ifdef查看是否已定义DEBUG(是否要为调试版本包含一些代码).或者甚至可以设置一个变量(我无法想象为什么会这样):

In your code you can use #ifdef to see if DEBUG is defined if you want some code included or not for debug builds. Or you can even set a variable (I can't imagine why you would want this):

#ifdef DEBUG
  BOOL isBuiltDebug = YES;
#else
  BOOL isBuiltDebug = NO;
#endif

嗯,另一种方法是在预处理器宏中定义一个布尔值,即:"Debug"配置为"DEBUG_BUILD = 1",而发布"配置为"DEBUG_BUILD = 0".然后,您可以在代码中使用该值:

Well, another way is to define a boolean value in a Preprocessor Macro, ie: "DEBUG_BUILD=1" for the Debug configuration, and "DEBUG_BUILD=0" for the Release configuration. Then you can use that value in your code:

if (DEBUG_BUILD) {
   ....
}

请小心不要使用与您的代码或可能包含的任何.h文件中的名称匹配的宏名称,因为预处理器将替换它,并且找到这些类型确实很痛苦错误.

Just be careful not to use a macro name that could match a name that is already in your code or in any .h file that you might include either, because the preprocessor will replace it and it's a real pain to find those kinds of bugs.

这篇关于在运行时检测iPhone是否正在运行Debug/Distribution版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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