如何在iPhone本身上访问iPhone的日志文件 [英] how to access my iphone's log file on the iphone itself

查看:135
本文介绍了如何在iPhone本身上访问iPhone的日志文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我的应用程序继续崩溃,并丢失了控制台中输出的所有日志.我决定越狱手机,并使用代码写入文件:

  +(void)Log:(NSString *)content{NSArray *路径= NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,是);NSString * docDir = [路径objectAtIndex:0];NSString * logFile = [docDir stringByAppendingString:@"/log.txt"];NSData * dataToWrite = [内容dataUsingEncoding:NSUTF8StringEncoding];NSFileHandle * outputFile = [NSFileHandle fileHandleForWritingAtPath:logFile];[outputFile seekToEndOfFile];[outputFile writeData:dataToWrite];[outputFile closeFile];} 

如果我设置了一个断点,则 outputFile 的值如下所示:/var/mobile/Applications/B8AB0D75-7FBE-4C5B-8D48-2ABCE9C7564D/Documents/log.txt

我通过cydia在手机上安装了vim,并且该目录中没有log.txt!(我已经使用 iphone隧道作为根SSH SSH进入了我的iPhone.再次尝试,我使用vim手动创建了log.txt并再次运行了代码..仍然没有任何内容附加到文件中..有什么想法吗?

解决方案

原来是对该文件的写权限.

So my app keeps on crashing and losing all the logs outputed in console. I decided to jailbreak the phone, and use this code to write to a file:

+(void)Log:(NSString *)content
{

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, 
                                                         NSUserDomainMask, YES); 
    NSString* docDir = [paths objectAtIndex:0];
    NSString * logFile = [docDir stringByAppendingString:@"/log.txt"];                             

    NSData *dataToWrite = [content dataUsingEncoding: NSUTF8StringEncoding];
    NSFileHandle* outputFile = [NSFileHandle fileHandleForWritingAtPath:logFile];
    [outputFile seekToEndOfFile];
    [outputFile writeData:dataToWrite];    
    [outputFile closeFile];
}

if I put a break point, the value of outputFile looks like this: /var/mobile/Applications/B8AB0D75-7FBE-4C5B-8D48-2ABCE9C7564D/Documents/log.txt

I installed vim on my phone via cydia, and there is no log.txt in the said directory! (I've SSH'd into my iPhone using iphone tunnel as root SSH. On another attempt, I manually created the log.txt using vim and ran the code again.. still nothing gets appended to the file.. any ideas?

解决方案

turns out to be a writing permission to the file.. so i just chmod'ed it and it works fine.. D'OH!

这篇关于如何在iPhone本身上访问iPhone的日志文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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