1. 写入文件
1 - (void)writelogToDocumentFolder 2 { 3 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 4 NSString *documentDirectory = [paths objectAtIndex:0]; 5 NSString *fileName = [NSString stringWithFormat:@"pandatv_file.log"]; 6 NSString *logFilePath = [documentDirectory stringByAppendingPathComponent:fileName]; 7 // 先删除已经存在的文件 8 NSFileManager *defaultManager = [NSFileManager defaultManager]; 9 [defaultManager removeItemAtPath:logFilePath error:nil]; 10 11 // 将log输入到文件 12 freopen([logFilePath cStringUsingEncoding:NSASCIIStringEncoding], "a+", stdout); 13 freopen([logFilePath cStringUsingEncoding:NSASCIIStringEncoding], "a+", stderr); 14 }