iPhone:如何从设备读取应用程序日志 [英] iPhone: How to read application logs from device

查看:1096
本文介绍了iPhone:如何从设备读取应用程序日志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法从iPhone设备读取应用程序日志?类似于Android的LogCat?

Is there a way to read the application logs from the iPhone device? Something similar to LogCat of Android?

推荐答案

正如Zoul所说,你可以在组织者中获得它们。但在此之前,您应该告诉应用程序将日志存储在Documents文件夹中。这样,当您在管理器中时,提取应用程序数据,您将在那里找到日志。

As Zoul said, you could obtain them in the Organizer. But prior to that, you should tell your application to store the logs in the Documents folder, for example. That way when you are in the Organizer,extract the application data and you will find the logs there.

现在,为了告诉您的应用重定向 NSLog()输出到文件,你应该这样做:

Now, in order to tell your app to redirect the NSLog() outputs to a file, you should do something like this:

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);

最后一句是实际重定向输出的句子。

The last sentence is the one that actually redirects the output.

因此,一旦完成,您的应用程序日志将存储在应用程序的文档文件夹中。

So once you have done that, your app logs will be stored in the application's documents folder.

您不知道如何提取应用程序数据吗? 此处你应该找出来。

Don't you know how to extract the application data? Here you shall find out.

我希望它可以帮助你。

这篇关于iPhone:如何从设备读取应用程序日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆