iOS发送crash崩溃日志报告

来源:互联网 发布:人体工学椅有用吗 知乎 编辑:程序博客网 时间:2024/05/29 14:16

Demo下载地址

在平时开发中,我们经常会遇到很多crash,如果项目没上线可以在代码中合成第三方的崩溃日志,便于我们记录查找问题所在。但是切记在上线之前把这些代码给去掉,不然的话审核会被苹果拒绝。因此个人参考写了崩溃记录日志,发送邮件给开发者,当然能不能审核过暂未尝试过。

但是这个方法也有一个弊端,因为调取的iPhone手机系统的邮件app去发送邮件,还需要配置一些东西,博主将链接写在下面

iOS系统自带邮件设置邮箱

void UncaughtExceptionHandler(NSException * exception){    /**     *  获取异常崩溃信息     */    NSArray * arr = [exception callStackSymbols];    NSString * reason = [exception reason];    NSString * name = [exception name];    NSString * url = [NSString stringWithFormat:@"========异常错误报告========\nname:%@\nreason:\n%@\ncallStackSymbols:\n%@",name,reason,[arr componentsJoinedByString:@"\n"]];        //写入沙盒    NSString * path = [applicationDocumentsDirectory() stringByAppendingPathComponent:@"Exception.txt"];    [url writeToFile:path atomically:YES encoding:NSUTF8StringEncoding error:nil];        NSString *exceptionString = [NSString stringWithFormat:@"[文件名:%s] [函数名:%s] [行号:%d] [异常:%@]",__FILE__,__FUNCTION__,__LINE__,exception];        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];    [formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];    NSString *dateStr = [formatter stringFromDate:[NSDate date]];//时间        NSString *iOS_Version = [[UIDevice currentDevice] systemVersion];//iOS系统版本    NSString *app_Version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];//app版本    NSString *iPhoneType = [Tool getiPhoneType];//iPhone机型        //发送邮件给开发者    NSString *urlStr = [NSString stringWithFormat:@"mailto:xx...xx@xx.com?subject=iOS客户端Crash报告&body=针对本次应用出现的故障,表示非常抱歉!感谢您的配合,发送这封邮件给我们的开发者,协助我们改善此应用,提高您的体验!<br>"                        "错误详情:<br>iOS_Version:%@<br>--------------------------<br>app_Version:%@<br>--------------------------<br>iPhoneType:%@<br>--------------------------<br>dateStr:%@<br>--------------------------<br>name:%@<br>--------------------------<br>reason:%@<br>---------------------<br>message:%@<br>---------------------<br>%@",                        iOS_Version,                        app_Version,                        iPhoneType,                        dateStr,                        name,                        reason,                        exceptionString,                        [arr componentsJoinedByString:@"<br>"]];        NSURL *mailUrl = [NSURL URLWithString:[urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];    [[UIApplication sharedApplication] openURL:mailUrl];}

崩溃日志如下:



原创粉丝点击