废话不说上代码,已经封装好
appPrefix.pch文件中 加入宏定义:
/*
判断 模拟器 or 真机
*/
#if TARGET_IPHONE_SIMULATOR
#define SIMULATOR 1
#elif TARGET_OS_IPHONE
#define SIMULATOR 0
#endif
在AppDelegate加入:
<pre name="code" class="objc">/*
输出Log到共享文档doc notes: 如果打开, 则真机连接xcode调试的时候 ,不在控制台输出日志
*/
- (void)redirectNSLogToDocumentFolderwithOpen:(BOOL) isOpen withNumLog: (int) num {
if (SIMULATOR == 0 ) {
if (isOpen) {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *fileName =[NSString stringWithFormat:@"Starfish_%@.log",[NSDate date]];
NSString *logFilePath = [documentsDirectory stringByAppendingPathComponent:f