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

查看:90
本文介绍了如何确定代码是否正在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.

但是在最终的应用商店版本(即,以发布模式运行)上,必须禁用所有这些功能(安全隐患)!

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-预处理,预处理器宏下检查项目的构建设置以进行调试,以确保已设置 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天全站免登陆