博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
腾讯Bugly异常崩溃SDK接入
阅读量:4633 次
发布时间:2019-06-09

本文共 2410 字,大约阅读时间需要 8 分钟。

首先登入Bugly,创建应用,记录下AppId

①下载SDK,通过Cocoapods集成

pod 'Bugly'                                                                    #腾讯异常崩溃日志服务

②导入头文件,并初始化

/** 腾讯Bugly */    #import 
//腾讯 bugly初始化 BuglyConfig * config = [[BuglyConfig alloc] init]; //Debug信息开关 config.debugMode = YES; config.channel = @"CallShow"; //卡顿监控开关 config.blockMonitorEnable = YES; //非正常退出事件记录开关 config.unexpectedTerminatingDetectionEnable = YES; //设置自定义日志上报的级别,默认不上报自定义日志 config.reportLogLevel = BuglyLogLevelWarn; config.version = HKBuildVersion; [Bugly startWithAppId:BUGLY_APP_ID config:config];

③设置用户唯一标识

[Bugly setUserIdentifier:accountInfo.openId];

④手动报告异常信息

//开启异常捕捉 NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler);void uncaughtExceptionHandler(NSException*exception){    [Bugly setTag:10086];    [Bugly reportException:exception];    // 可以通过exception对象获取一些崩溃信息,我们就是通过这些崩溃信息来进行解析的,例如下面的symbols数组就是我们的崩溃堆栈。    NSArray  *callStack = [exception callStackSymbols];        NSString *reason = [exception reason];        NSString *name = [exception name];        NSString *dateString = [NSString getTimeStamp];        NSString *systemName = [[UIDevice currentDevice] systemName];//系统        NSString *deviceModel = [[UIDevice currentDevice] model];//设备        NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];        NSString *bundleIdentifier = infoDict[@"CFBundleIdentifier"];        NSString* versionNum = [infoDict objectForKey:@"CFBundleShortVersionString"];        NSMutableString *systemNameVersion = [[NSMutableString alloc] initWithFormat:@"%@ %@",[[UIDevice currentDevice] systemName],[[UIDevice currentDevice] systemVersion]];//手机系统版本    //NSString *content = [NSString stringWithFormat:@"%@%@",callStack,systemNameVersion];    NSString *content = [NSString stringWithFormat:@"\n\n\n========异常错误报告========\n错误时间:%@ 系统:%@ 设备:%@ 手机系统版本:%@ \n当前版本:%@ 当前唯一标示符:%@\n\n错误名称:%@\n错误原因:\n%@\ncallStackSymbols:\n%@\n\n========异常错误结束========\n",dateString,systemName,deviceModel,systemNameVersion,versionNum,bundleIdentifier,name,reason,[callStack componentsJoinedByString:@"\n"]];    HKLog(@"CRASH: %@", content);    // Internal error reporting}

⑤编写Crash测试代码

- (void)crashTest {    NSArray *ary = [NSArray arrayWithObjects:@"dsfs", @"dsfsd", nil];    NSLog(@"%@", ary[4]);  // 会触发 uncaughtExceptionHandler 方法}

⑥网址

 

转载于:https://www.cnblogs.com/StevenHuSir/p/Bugly.html

你可能感兴趣的文章
大智慧面试经验
查看>>
比特币脚本及交易分析 - 智能合约雏形
查看>>
kafka消息会不会丢失
查看>>
codeforces-1132 (div2)
查看>>
简单入门dos程序
查看>>
linux下occi操作oracle数据库,中文乱码的问题
查看>>
JS原型与原型链
查看>>
SVG.js 笔记 (一)
查看>>
struts2笔记01-环境搭建
查看>>
appium 控件定位
查看>>
oracle sql 获取本季度所有月份,上季度所有月份
查看>>
VUE的组件DEMO
查看>>
xshell连接Linux、ngix部署
查看>>
XCODE 6.1.1 配置GLFW
查看>>
vue element 关闭当前tab 跳转到上一路由
查看>>
4、面向对象
查看>>
[NOI2005]聪聪与可可(期望dp)
查看>>
POJ 3723
查看>>
解决sql2014的distribution系统库distribution.mdf过大问题
查看>>
Maven的安装
查看>>