首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 操作系统 >

把 iOS app logs 写下 documents 文件夹

2013-12-10 
把 iOS app logs 写入 documents 文件夹Now, in order to tell your app to redirect the NSLog() outputs

把 iOS app logs 写入 documents 文件夹
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.

  


BTW: Organizer shows the console also, which has the NSLog output. The device has to be provisioned and have settings->developer settings->Logging turned on.

热点排行