如何确定代码是否在 DEBUG/RELEASE 构建中运行? [英] How to determine whether code is running in DEBUG / RELEASE build?

查看:19
本文介绍了如何确定代码是否在 DEBUG/RELEASE 构建中运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个处理敏感信用卡数据的应用.

I am making an app that processes sensitive credit card data.

如果我的代码在调试模式下运行,我想将此数据记录到控制台并进行一些文件转储.

If my code is running in debug mode I want to log this data to the console and make some file dumps.

然而,在最终的 appstore 版本中(即当它在发布模式下运行时),必须禁用所有这些(安全隐患)!

However on the final appstore version (ie when it is running in release mode) it is essential all of this is disabled (security hazard)!

我会尽量回答我的问题;所以问题变成了'这个解决方案是正确的还是最好的方法?'

I will try to answer my question as best I can; so the question becomes 'Is this solution path the right or best way to do it?'

// add `IS_DEBUG=1` to your debug build preprocessor settings  

#if( IS_DEBUG )  
#define MYLog(args...) NSLog(args)  
#else  
#define MYLog(args...)  
#endif  

推荐答案

在 'Apple LLVM - Preprocessing'、'Preprocessor Macros' 下检查您项目的构建设置以进行调试,以确保正在设置 DEBUG- 通过选择项目并单击构建设置选项卡来执行此操作.搜索 DEBUG 并查看是否确实设置了 DEBUG.

Check your project's build settings under 'Apple LLVM - Preprocessing', 'Preprocessor Macros' for debug to ensure that DEBUG is being set - do this by selecting the project and clicking on the build settings tab. Search for DEBUG and look to see if indeed DEBUG is being set.

请注意.您可能会看到 DEBUG 更改为另一个变量名称,例如 DEBUG_MODE.

Pay attention though. You may see DEBUG changed to another variable name such as DEBUG_MODE.

然后有条件地在源文件中为 DEBUG 编码

then conditionally code for DEBUG in your source files

#ifdef DEBUG

// Something to log your sensitive data here

#else

// 

#endif

这篇关于如何确定代码是否在 DEBUG/RELEASE 构建中运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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