-
Notifications
You must be signed in to change notification settings - Fork 123
如何仅在Debug环境中使用
HDB-Li edited this page Jun 8, 2018
·
1 revision
Click here for an English introduction
通常情况下,当你只想在Debug环境下使用某个库时,你会在Podfile里这样写入一行pod 'LLDebugTool' ,:configurations => ['Debug']。
当您以这种方式进行集成时,您将发现您的代码在Release环境中会有许多报错,您可以通过以下方式解决大多数的LLDebugTool和LLConfig锁造成的报错。您可以通过在#ifdef DEBUG和#endif来包裹着LLDebugTool的代码,来确保该代码只在Debug环境中编译。
#ifdef DEBUG
#import "LLDebug.h"
#endif
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
#ifdef DEBUG
[LLConfig sharedConfig].userIdentity = @"Your user Identity";
[[LLDebugTool sharedTool] startWorking];
#endif
}
如果它是LLog宏或其他的LLog宏,那么这样做就显得很傻,因为您需要在每个LLog宏前后添加#ifdef DEBUG和#endif。更好的解决这个问题,可以查看LLDebugToolMacros.h这个文件,并将以下代码复制到PCH文件中。
// Your PCH file.
#ifndef DEBUG
#define LLog(fmt, ...) NSLog(fmt)
#define LLog_Event(event , fmt , ...) NSLog(fmt)
#define LLog_Alert(fmt, ...) NSLog(fmt)
#define LLog_Alert_Event(event, fmt , ...) NSLog(fmt)
#define LLog_Warning(fmt, ...) NSLog(fmt)
#define LLog_Warning_Event(event, fmt , ...) NSLog(fmt)
#define LLog_Error(fmt, ...) NSLog(fmt)
#define LLog_Error_Event(event, fmt , ...) NSLog(fmt)
#endif
这样你就解决了全部的报错情况,LLog宏会在DEBUG环境时调用LLDebugTool的方法,而在Release环境时调用NSLog的方法。
稍后更新。