iOS 使用 printf 调试真实设备
在 Xcode Organizer 中,控制台 - 我可以读取 NSLog
输出,但不能读取 printf()
。是否可以在真实设备上读取 printf()
结果,就像在模拟器中一样?
In Xcode Organizer, Console - I can read the NSLog
output, but not printf()
. Is this possible to read printf()
result on the real device, the same like in simulator?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
最简单的解决方案是在项目中全局重载 printf 函数,并将其替换为 NSLog 输出
Easiest solution would be to overload printf function globally in your project and replace it with NSLog output
正如 Nick Lockwood 在上面的评论之一中所说, printf 打印到 stdout,但 NSLog 打印到 stderr。您可以使用 fprintf 打印到 stderr(Xcode 控制台),而不是使用 printf,如下所示:
As Nick Lockwood said in one of the comments above, printf prints to stdout but NSLog prints to stderr. You can use fprintf to print to stderr (the Xcode console) instead of using printf, like this:
您可以运行以下命令以仅打印到设备的控制台:
您还需要 #include显式声明 syslog 和 LOG_WARNING
You can run the following command to print only to device's console:
You will also need to #include <sys/syslog.h> for syslog and LOG_WARNING to be explicitly declared
Skippy,printf()是c的输出语句而不是Objective C,所以在真实设备中printf()也不起作用。
Skippy,printf() is the output statement for c not for Objective C,SO in real device also printf() is not work.