iOS: #ifdef DEBUG
2015-09-08 10:08
441 查看
开发时,经常用到NSLog,但release是又想一次过清掉all NSLog,方法是:在xxx-Prefix.pch里添加
[cpp] view
plaincopy
#ifdef DEBUG
# define DLog(...) NSLog(__VA_ARGS__)
#else
# define DLog(...) /* */
#endif
#define ALog(...) NSLog(__VA_ARGS__)
When you want to log only in debug builds use DLog(). In release builds DLog() will be compiled as an empty comment. Otherwise use ALog() for logging in both debug and release
builds. (A as in always.)
那么"DEBUG"在哪里定义的呢? 在 "Target > Build Settings > Preprocessor Macros > Debug" 里有一个"DEBUG=1"。
当你Run, Test, Analyze时,就属于debug mode,当Profile, Archive时就属于release mode。见你的ios project的"Edit Scheme..."
#ifdef DEBUG的另外一个用处是:用于push notification。sandbox device token and production device token一定不能mix在一起,否则就可能有些device收不到。见/article/8005010.html
因此我们需要为reg device token准备2个url
[cpp] view
plaincopy
#ifdef DEBUG
NSString * const REG_URL=@"http://xxxx/reg_dev_token";
#else
NSString * const REG_URL=@"http://xxxx/reg_production_token";
#endif
[cpp] view
plaincopy
#ifdef DEBUG
# define DLog(...) NSLog(__VA_ARGS__)
#else
# define DLog(...) /* */
#endif
#define ALog(...) NSLog(__VA_ARGS__)
When you want to log only in debug builds use DLog(). In release builds DLog() will be compiled as an empty comment. Otherwise use ALog() for logging in both debug and release
builds. (A as in always.)
那么"DEBUG"在哪里定义的呢? 在 "Target > Build Settings > Preprocessor Macros > Debug" 里有一个"DEBUG=1"。
当你Run, Test, Analyze时,就属于debug mode,当Profile, Archive时就属于release mode。见你的ios project的"Edit Scheme..."
#ifdef DEBUG的另外一个用处是:用于push notification。sandbox device token and production device token一定不能mix在一起,否则就可能有些device收不到。见/article/8005010.html
因此我们需要为reg device token准备2个url
[cpp] view
plaincopy
#ifdef DEBUG
NSString * const REG_URL=@"http://xxxx/reg_dev_token";
#else
NSString * const REG_URL=@"http://xxxx/reg_production_token";
#endif
相关文章推荐
- 快开学了,继续码一码iOS开发~
- ios-xcode真机测试时报错001 process launch failed
- iOS开发--通过MultipeerConnectivity完成蓝牙通讯
- ios 实时刷新屏幕
- iOS开发--通过MultipeerConnectivity完成蓝牙通讯
- ios开发中遇到的奇葩问题
- iOS项目开发实战——获取本机IP地址
- iOS编写质量代码
- IOS开发小技巧
- IOS中NSFileHandle的基本用法
- iOS项目开发实战——弹出提示对话框
- [iOS翻译] Cocoa编码规范
- IOS时间与日期类的使用
- iOS项目开发实战——获取系统当前时间
- ios Crash闪退日志获取和上传至服务器(NSSetUncaughtExceptionHandler)
- iOS开发系列--音频播放、录音、视频播放、拍照、视频录制
- iOS-添加pch文件
- iOS:删除、插入、移动单元格
- iOS开发日记15-强制弹出系统键盘(禁用搜狗键盘)
- 加载网页——iOS学习连载28