如何确定我的iOS应用程序正在调试模式下运行?
守则:如何确定我的iOS应用程序正在调试模式下运行?,ios,objective-c,swift,compilation,Ios,Objective C,Swift,Compilation,守则: #if DEBUG let iAmInDebugMode = true #else let iAmInDebugMode = false #endif 项目设置: 方案设置: 结果是: println(iAmInDebugMode) // false 为什么??我做错了什么?运行时 NSDictionary* env = [[NSProcessInfo processInfo] environment]; if ([[env valueForKey:@"debu
#if DEBUG
let iAmInDebugMode = true
#else
let iAmInDebugMode = false
#endif
项目设置:
方案设置:
结果是:
println(iAmInDebugMode) // false
为什么??我做错了什么?运行时
NSDictionary* env = [[NSProcessInfo processInfo] environment];
if ([[env valueForKey:@"debugger"] isEqual:@"true"]) {
NSLog(@"debugger yes");
}
else {
NSLog(@"debugger no");
}
编译时
#ifdef DEBUG
// Something to log your sensitive data here
#else
//
#endif
在swift中,它不会像这样工作,您需要在其他swift标志内设置标志
-D DEBUG
,然后它才能工作。您可以获得有关生成配置标志的更多详细信息
我添加了答案,您需要在其他\u swift\u标志中设置标志幸运的是,您必须自己添加“debugger”环境变量。