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

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

问题描述



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



然而,在最终的appstore版本(即当它在发布模式下运行时),这一切都是禁用的(安全隐患)!



我会尽可能地回答我的问题;所以这个问题就变成了这个解决方案路径是正确的还是最好的方式呢?'

  //将`IS_DEBUG = 1'添加到调试版本的预处理器设置

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


解决方案

在Apple LVM - 预处理,预处理器宏下检查项目的构建设置以进行调试,以确保正在设置DEBUG - 通过选择项目并单击构建设置选项卡。搜索'DEBUG'并查看是否正在设置DEBUG。



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





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

  #ifdef DEBUG 

//在这里记录敏感数据的东西

#else

//

#endif


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  

解决方案

Check your project's build settings under 'Apple LVM - 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.

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

then conditionally code for DEBUG in your source files

#ifdef DEBUG

// Something to log your sensitive data here

#else

// 

#endif

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

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