在设备上记录数据并检索日志 [英] Logging data on device and retrieving the log
问题描述
在Xcode中的调试版本中,无论我是使用模拟器还是实际设备,NSLog,printf,fprintf assert和NSAssert语句都出现在控制台上
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
如果我现在在设备上运行发布版本(比如我发送测试航班版本并在我的iPhone上加大;这将是一个发布版本),其中哪些(如果有的话)被记录?
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?
如何检索日志?
NSLog实际上是否在发布版本中输出了什么?决定因素是什么?无论是写入stdout还是stderr?只有stderr写入设备日志?这是否意味着我必须使用fprintf?是否已将任何内容写入设备日志?甚至还有这样的事情吗?如果是这样,如何接受?
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?
推荐答案
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *fileName =[NSString stringWithFormat:@"%@.log",[NSDate date]];
NSString *logFilePath = [documentsDirectory stringByAppendingPathComponent:fileName];
freopen([logFilePath cStringUsingEncoding:NSASCIIStringEncoding],"a+",stderr);
只需在应用程序中添加此代码块:didFinishLaunchingWithOptions
app委托文件中的方法,它将在iPhone上的app文档目录中创建一个日志文件,记录所有控制台日志事件。您需要从iTunes导入此文件以查看所有控制台事件。
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.
注意:在.plist文件中,确保应用程序支持iTunes文件共享
存在且设置为 YES
,以便您可以通过iTunes访问。
Note: In the .plist file make sure that Application supports iTunes file sharing
is exists and is set to YES
so that you can access through iTunes.
获取日志文件:
启动itunes,在您的设备连接选择应用程序后 - 选择您的应用程序 - 在Augument文档中,您将获得您的文件。然后,您可以将其保存到磁盘
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
这篇关于在设备上记录数据并检索日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!