iOS: #ifdef DEBUG

開發時,常常用到NSLog,但release是又想一次過清掉all NSLog,方法是:在xxx-Prefix.pch裏添加ios

 

[cpp]  view plain copy
 
  1. #ifdef DEBUG  
  2. #    define DLog(...) NSLog(__VA_ARGS__)  
  3. #else  
  4. #    define DLog(...) /* */  
  5. #endif  
  6. #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.)ui

 

 

那麼"DEBUG"在哪裏定義的呢? 在 "Target > Build Settings > Preprocessor Macros > Debug" 裏有一個"DEBUG=1"。url

 

當你Run, Test, Analyze時,就屬於debug mode,當Profile, Archive時就屬於release mode。見你的ios project的"Edit Scheme..."spa

 

#ifdef DEBUG的另一個用處是:用於push notification。sandbox device token and production device token必定不能mix在一塊兒,不然就可能有些device收不到。見http://blog.csdn.net/totogogo/article/details/8035095.net

 

所以咱們須要爲reg device token準備2個urldebug

 

[cpp]  view plain copy
 
    1. #ifdef DEBUG  
    2.     NSString * const REG_URL=@"http://xxxx/reg_dev_token";  
    3. #else  
    4.     NSString * const REG_URL=@"http://xxxx/reg_production_token";  
    5. #endif  
相關文章
相關標籤/搜索