首先登入Bugly,创建应用,记录下AppId
①下载SDK,通过Cocoapods集成
pod 'Bugly' #腾讯异常崩溃日志服务
②导入头文件,并初始化
/** 腾讯Bugly */#import <Bugly/Bugly.h>//腾讯 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://bugly.qq.com/v2/index
https://bugly.qq.com/docs/user-guide/advance-features-ios/?v=20181014122344