相关疑难解决方法(0)

检测iOS应用程序是否在调试器中运行

我将应用程序设置为将调试输出发送到控制台或日志文件.现在,我想在代码中决定是否

  • 它在调试器(或模拟器)中运行,因此有一个控制台窗口,我想直接读取输出或如果
  • 没有控制台窗口,因此输出应重定向到文件.

有没有办法确定应用程序是否在调试器中运行?

iphone debugging objective-c ios

43
推荐指数
6
解决办法
1万
查看次数

检测是否正在从Xcode运行Swift应用程序

我想以编程方式确定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)

xcode ios swift

19
推荐指数
1
解决办法
2971
查看次数

标签 统计

ios ×2

debugging ×1

iphone ×1

objective-c ×1

swift ×1

xcode ×1