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!