在设备上记录数据并检索日志
在 Xcode 中的调试构建中,无论我使用的是模拟器还是实际设备,NSLog、printf、fprintf 断言和 NSAssert 语句都会出现在控制台上
如果我现在在设备上运行发布构建(假设我发送一个测试)飞行构建并在我的 iPhone 上进行放大;这将是一个发布构建),其中哪些(如果有)正在被记录?
以及如何检索日志?
NSLog 实际上在发布版本中输出一些内容吗?决定因素是什么?是写入stdout还是stderr?仅 stderr 写入设备日志吗?这是否意味着我必须使用 fprintf ?设备日志中是否写入了任何内容?有这样的事吗?如果可以的话,如何领取呢?
有人可以澄清一下情况吗?
On a debug build in Xcode, regardless of whether I am using the simulator or an actual device, NSLog, printf, fprintf assert and NSAssert statements come out on the console
If I now run a release build on the device (say I send a test flight build and big it up on my iPhone; this will be a release build), which of these (if any) are getting recorded?
And how do I retrieve the log?
Does NSLog actually output something on release build? What is the determining factor? Whether it is writing to stdout or stderr? is only stderr written to device log? Does this mean I have to use fprintf? Is ANYTHING written to device log? is there even such a thing? If so, how to pick it up?
Could someone clarify the situation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
在 Xcode 6.1.1 中,您可以通过执行以下操作查看 NSLog 输出。但是,我不确定它是否可以让您查看太早以前的日志。我只看到它回到了几个小时。
无论如何,步骤如下:
In Xcode 6.1.1, you can view the NSLog output by doing the following. However, I'm not sure if it lets you see logs from too far back in time. I've only seen it go back up to a couple hours.
In any case, here are the steps:
只需在应用程序委托文件中的
application:didFinishLaunchingWithOptions
方法中添加此代码块,它将在 iPhone 上的应用程序文档目录中创建一个日志文件,用于记录所有控制台日志事件。您需要从 iTunes 导入此文件才能查看所有控制台事件。注意:在 .plist 文件中,确保
Applicationsupports iTunes filesharing
存在并设置为YES
,以便您可以通过 iTunes 访问。获取日志文件:
启动 itunes,在您的设备连接后选择应用程序 - 选择您的应用程序 - 在 Augument Document 中您将获得您的文件。然后您可以将其保存到磁盘上
Just add this block of code in
application:didFinishLaunchingWithOptions
method in the app delegate file and it will create a log file in app document directory on iPhone which logs all console log events. You need to import this file from iTunes to see all console events.Note: In the .plist file make sure that
Application supports iTunes file sharing
is exists and is set toYES
so that you can access through iTunes.To get Logfiles :
Launch itunes, after your device has connected select Apps - select your App - in Augument Document you will get your file. You can then save it to your disk
在 swift 4.0+ 中,Shyl 的代码将更改为,
所有其他过程与 Shyl 解释的相同
In swift 4.0+, the code of Shyl will changes to,
all other process are same that explained by Shyl
NSLog 在生产版本中写入设备日志,您可以通过将 iPhone 连接到系统并使用 Organizer 来检查这一点。在管理器中选择您的 iPhone,单击“设备日志”。您将在日志中看到所有 NSLog 输出。
NSLog is written to device log in production release and you can check this by connecting your iPhone to your system and using Organizer. Select your iPhone in the organizer, click Device Logs. You would see all NSLog outputs in the log.
我发现 APPLE 的这个链接信息非常丰富且完整。
它几乎为您提供了查看或访问设备日志的所有选项,无论它们是否连接到您的开发计算机。
https://developer.apple.com/library/ios/qa/qa1747 /_index.html
I found this link from APPLE very informative and complete.
It pretty much gives you all the options to see or access logs of the device whether or not they are connected to your dev machine.
https://developer.apple.com/library/ios/qa/qa1747/_index.html
我知道这是一个旧线程,但您也可以访问设备日志:
设置 ->隐私->分析->数据
希望这有帮助
问候
I know this is an old thread but you can also have access to the device logs going to:
Settings -> Privacy -> Analytics -> Data
Hope this help
Regards
是的,NSLog 在设备上输出。您可以将设备连接到 Mac 并使用 Xcode Organizer 工具查看其输出。
Yes, NSLog outputs on the device. You can see it's outputs with your device connected to your Mac and using Xcode Organizer tool.
如果您使用 Testflight SDK,则可以使用其 远程日志记录功能。
If you use Testflight SDK, you can capture all logs with their Remote Logging feature.
我认为在 Xcode 9.3 中,设备日志屏幕已移至新位置。请参考以下链接。
在 Xcode 中运行时获取设备日志
I think in Xcode 9.3 the device log screen has been moved to a new location.Kindly refer the following link.
Get device logs at runtime in Xcode