printStackTrace

转载 2016年06月01日 16:04:10
- (void)printStackTrace:(NSException *)e//要写入log文件的信息
{
    NSString *stack = [[e userInfo] objectForKey:NSStackTraceKey];
    NSMutableArray *args = [NSMutableArray arrayWithCapacity:20];
    if (stack) {
        NSTask *ls = [[NSTask alloc] init];
        NSString *pid = [[NSNumber numberWithInt:[[NSProcessInfo processInfo] processIdentifier]] stringValue];
        [args addObject:@"-p"];//-p
        [args addObject:pid];
        [args addObjectsFromArray:[stack componentsSeparatedByString:@"  "]];
        // Note: function addresses are separated by double spaces, not a single space.
        [ls setLaunchPath:@"/usr/bin/atos"];//xcrun atos
        [ls setArguments:args];
       // [ls launch];
        NSPipe *pipe;
        pipe = [NSPipe pipe];
        [ls setStandardOutput: pipe];
        NSFileHandle *file;
        file = [pipe fileHandleForReading];
        [ls launch];
        NSData *data;
        data = [file readDataToEndOfFile];
        NSString *string;
        string = [[NSString alloc] initWithData: data
                                       encoding: NSUTF8StringEncoding];
        NSString *strFormat = [NSString stringWithFormat:@"\n\n*************************exception begin\nexception time: %@\n%@\n*************************exception end\n\n",[NSDate date] ,string];
        DDLogCError(strFormat);

    } else {
        DDLogCError(@"No stack trace available.");
    }
}
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:printStackTrace
举报原因:
原因补充:

(最多只允许输入30个字)