前言:
最近项目打包分发给客服部门测试,有反馈说在iPhone 7,系统10.1中点击登录之后会有crash的问题,但是我们手上的手机没有问题。又不能把人家的手机拿过来调试,而且可能会有隐藏的crash,平时在测试过程中没有测试出来,又或者是不易复现的bug,于是乎就想到添加错误记录日志~~~
1、只需要QQ号就可以申请账号了
2、新建产品
之前我已经新建一个项目了。
3、填写相关信息
保存之后就可以获取APP ID、 APP Key
4、下载相关的demo,导入相关文件,文档写的很清楚。基本设置页很简单。可根据官方文档设置
5、在AppDelegate.m中导入
#import <Bugly/Bugly.h>
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[Bugly startWithAppId:BUGLY_APP_ID];
// [self setupBugly];
return YES;
}
在ViewController.m写一个简单点的点击按钮会crash的代码。
- (void)viewDidLoad {
[super viewDidLoad];
//没有实现按钮的点击事件
UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 100, 30)];
btn.backgroundColor = [UIColor redColor];
[btn addTarget:self action:@selector(onClick1) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
}
6、在模拟器运行之后,点击按钮,看下Bugly中会有什么展示信息
7、在异常报告的奔溃分析中,可以看到crash的原因,点击进去还可以查看详情,能看到相关的解决方案,和一些crash时系统运行了哪些方法,相关的手机信息等。
解决方案:
相关的手机信息:
堆栈信息:
8、也可以自定义bugly的相关设置
- (void)setupBugly {
BuglyConfig * config = [[BuglyConfig alloc] init];
// 非正常退出事件(SIGKILL)
config.unexpectedTerminatingDetectionEnable = YES;
// Open the debug mode to print the sdk log message.
// Default value is NO, please DISABLE it in your RELEASE version.
//上传时改为NO
#if DEBUG
config.debugMode = YES;//开启SDK日志
#endif
config.reportLogLevel = BuglyLogLevelWarn;
//卡顿监控
config.blockMonitorEnable = YES;
// Set the STUCK THRESHOLD time, when STUCK time > THRESHOLD it will record an event and report data when the app launched next time.
// Default value is 3.5 second.
config.blockMonitorTimeout = 1.5;
//渠道标识
config.channel = @"Yuna";
config.delegate = self;
//进程内还原符号
config.symbolicateInProcessEnable = YES;
// NOTE:Required
// Start the Bugly sdk with APP_ID and your config
[Bugly startWithAppId:BUGLY_APP_ID
#if DEBUG
developmentDevice:YES
#endif
config:config];
// Set the customizd tag thats config in your APP registerd on the bugly.qq.com
// [Bugly setTag:1799];
[Bugly setUserIdentifier:[NSString stringWithFormat:@"User: %@", [UIDevice currentDevice].name]];
//+(NSProcessInfo*)processInfo //返回当前进程的信息
//-(NSString*)processName //返回当前正在执行的进程名称
[Bugly setUserValue:[NSProcessInfo processInfo].processName forKey:@"Process"];
}
在AppDelegate.m中调用自定义的Bugly配置,不用系统自带的。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//[Bugly startWithAppId:BUGLY_APP_ID];
[self setupBugly];
return YES;
}
注意:
我之前测试的时候,在Bugly中看不到crash的日志,主要要确保bugly的初始化要在你crash代码之前。相关常见问题见官方文档