有些时候测试,需要通过log日志来调式代码,发现问题
可以将打印的log日志保存在APP本地文件中
//Save NSlog print information to a file in the Document directory
- (void)redirectNSlogToDocumentFolder{
UIDevice *device = [UIDevice currentDevice];
if ([[device model] isEqualToString:@"Simulator"]) {
return;
}
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDirectory = [paths objectAtIndex:0];
NSString *fileName = [NSString stringWithFormat:@"test.log"];
NSString *logFilePath = [documentDirectory stringByAppendingPathComponent:fileName];
// Delete existing files
NSFileManager *defaultManager = [NSFileManager defaultManager];
[defaultManager removeItemAtPath:logFilePath error:nil];
//Enter the log into the file
freopen([logFilePath cStringUsingEncoding:NSASCIIStringEncoding], "a+", stdout);
freopen([logFilePath cStringUsingEncoding:NSASCIIStringEncoding], "a+", stderr);
}
通过iTunes下载log文件