查看直接在模拟器中运行的应用程序的 NSLog,而不是通过 Xcode

发布于 2025-01-06 21:55:57 字数 96 浏览 5 评论 0原文

当我不通过 Xcode 运行代码时,有什么方法可以查看在 iOS 模拟器中运行的应用程序的控制台日志吗?我直接从模拟器中打开应用程序。我可以在某处看到打印的 NSLog 语句吗?

Is there any way I can see the console logs of an app running in the iOS simulator when I do not run the code via Xcode? I am directly opening the app from within the simulator. Can I see the NSLog statements printing somewhere?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

空城旧梦 2025-01-13 21:55:57

是的。这是来自 工具工作流程指南iOS

在模拟器中运行应用程序时,您可以访问应用程序的控制台
登录控制台应用程序(位于 /Applications/Utilities 中)。

Yes. Here's a quote from Tools Workflow Guide for iOS:

When running your app in a simulator, you can access the app’s console
logs in the Console app (located in /Applications/Utilities).

花落人断肠 2025-01-13 21:55:57

来自 BYU CocoaHeads

重定向NSLog()

有时,您可能希望将 NSLog() 输出重定向到文件,以便更方便地检查它。 NSLog() 的工作原理是将消息输出到 STDERR,因此您需要做的就是将 STDERR 流重定向到文件,然后您就可以很好,可以走了。以下代码会将其重定向到桌面上的文件:

 int fd = creat("/Users/dave/Desktop/my_log",
                       S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
    关闭(STDERR_FILENO);
    dup(fd);
    关闭(fd);
    NSLog(@"这将被写入 my_log");

这只会影响来自应用程序的 NSLog() 调用。

From BYU CocoaHeads:

Redirected NSLog()

Occasionally, you may want to redirect your NSLog() output to a file so that you can examine it more conveniently. NSLog() works by outputting messages to STDERR, so all you need to do is redirect the STDERR stream to a file, and you're good to go. The following code will redirect it to a file on your desktop:

    int fd = creat("/Users/dave/Desktop/my_log",
                       S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
    close(STDERR_FILENO);
    dup(fd);
    close(fd);
    NSLog(@"this will be written to my_log");

This will only affect NSLog() calls from your application.

梦在深巷 2025-01-13 21:55:57

我可以设法在 MAC 操作系统中的“控制台”应用程序中查看日志。

I could manage to see the logs in "Console" application in MAC OS.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文