iOS: #ifdef DEBUG
2015-10-23 17:11
337 查看
开发时,经常用到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动态管理AutoLayout的约束NSLayoutConstraint
- ios 摇一摇功能
- iOS清除缓存
- 二叉树-你必须要懂!(二叉树相关算法实现-iOS)
- iOS开发上传图片的方法
- iOS 实现类似Scale9图片
- iOS.Performance-trick-presentViewController-is-so-slow-in-didSelectRowAtIndexPath
- ios手机定位 -- 高德地图
- 【IOS 开发学习总结-OC-67】Quartz 2D绘图(4-4)——图形变换+填充处理+core image 滤镜
- ios开发从.plist文件中获取数据
- iOS测算文本高度
- 【IOS 开发学习总结-OC-66】Quartz 2D绘图(4-3)——绘制曲线+在内存中绘图+绘制位图
- 【IOS 开发学习总结-OC-65】Quartz 2D绘图(4-2)——绘制文本+设置阴影+使用路径
- iOS9.0 生成证书流程一(非推送)
- 【IOS 开发学习总结-OC-64】Quartz 2D绘图(4-1)——Quartz 2D绘图基础+点线模式
- IOS 通过POST方式与服务器通信
- iOS开发 AFNetworking2.5的使用
- iOS 退出多个页面 pop多个页面
- 自动布局之autoresizingMask
- IOS 通过GET方式与服务器通信