我将应用程序设置为将调试输出发送到控制台或日志文件.现在,我想在代码中决定是否
有没有办法确定应用程序是否在调试器中运行?
我想以编程方式确定iOS应用程序是否直接从XCode运行(在模拟器中或在系留设备上).我已经尝试了这里描述的-D DEBUG解决方案,但是当我从Xcode断开并重新运行应用程序时,它仍然认为它处于调试模式.我认为我正在寻找的是这个函数的Swift版本
#include <assert.h>
#include <stdbool.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/sysctl.h>
static bool AmIBeingDebugged(void)
// Returns true if the current process is being debugged (either
// running under the debugger or has a debugger attached post facto).
{
int junk;
int mib[4];
struct kinfo_proc info;
size_t size;
// Initialize the flags so that, if sysctl fails for some bizarre
// reason, we get a predictable result.
info.kp_proc.p_flag = 0;
// Initialize mib, which tells sysctl …Run Code Online (Sandbox Code Playgroud)