ios通过代码方式获取crash日志

1.新建GUncaughtExceptionHandler

+ (void)setDefaultHandler

{

    NSSetUncaughtExceptionHandler (&UncaughtExceptionHandler);

}

并实现方法

void UncaughtExceptionHandler(NSException *exception)

{

    NSArray *arr = [exception callStackSymbols];

    

    NSString*realErr1=[arr objectAtIndex:3];

    NSString *error1 = [realErr1 substringFromIndex:51];

    

    NSString * realErr2=[arr objectAtIndex:4];

    NSString *error2 = [realErr2 substringFromIndex:51];

    NSString * machineName =[Device machineName];

    NSString * error=[NSString stringWithFormat:@"%@=====>>>>>%@=====>>>>>%@--%@",machineName,error2,error1,exception.reason];

    JSONDAO*jsonDao =[[JSONDAO alloc]init];

    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];

    [dateFormatter setDateFormat: @"yy-MM-dd"];

    NSString*newTime=[dateFormatter stringFromDate:[YlwSingleMode GetCorrectiondate]];

    

    NSDate *lastDay = [NSDate dateWithTimeInterval:-24*60*60 sinceDate:[YlwSingleMode GetCorrectiondate]];

    NSString*oldTime=[dateFormatter stringFromDate:lastDay];

    [jsonDao updateSoftError:newTime errorlog:error todayDateString:oldTime];

}

2appdelegate调用方法

[GUncaughtExceptionHandler setDefaultHandler];

 

posted on 2016-01-29 17:41  Baymax01  阅读(304)  评论(0编辑  收藏  举报

导航