BugTool.m 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. //
  2. // BugTool.m
  3. // Unity-iPhone
  4. //
  5. // Created by duowan123 on 2022/4/6.
  6. //
  7. #import "BugTool.h"
  8. #import "AvoidCrash.h"
  9. #import <Bugly/Bugly.h>
  10. @implementation BugTool
  11. +(void)startAvoidBug{
  12. //bugly抓取
  13. NSString * bundleIdentifier = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleIdentifier"];
  14. if ([bundleIdentifier isEqualToString:@"com.Oujia.Run"]){
  15. [Bugly startWithAppId:@"36a0c05291"];
  16. }else if ([bundleIdentifier isEqualToString:@"com.Oujia.Dance"]){
  17. [Bugly startWithAppId:@"403d275730"];
  18. }else if ([bundleIdentifier isEqualToString:@"com.Oujia.Tricycle"]){
  19. [Bugly startWithAppId:@"60d408c425"];
  20. }
  21. //AvoidCrash防奔溃 + bug闪退信息上报
  22. [AvoidCrash makeAllEffective];
  23. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dealwithCrashMessage:) name:AvoidCrashNotification object:nil];
  24. }
  25. - (void)dealwithCrashMessage:(NSNotification *)note{
  26. NSDictionary *info = note.userInfo;
  27. NSString *errorReason = [NSString stringWithFormat:@"【ErrorReason】%@========【ErrorPlace】%@========【DefaultToDo】%@========【ErrorName】%@", info[@"errorReason"], info[@"errorPlace"], info[@"defaultToDo"], info[@"errorName"]];
  28. NSLog(@"errorReason = %@",errorReason);
  29. NSArray *callStack = info[@"callStackSymbols"];
  30. [self reportErrorName:@"Bugly_ErrorName_AvoidCrash" errorReason:errorReason callStack:callStack extraInfo:nil];
  31. }
  32. /** 上报错误信息 */
  33. - (void)reportErrorName:(NSString *)errorName errorReason:(NSString *)errorReason callStack:(NSArray *)aStackArray extraInfo:(NSDictionary *)info{
  34. [Bugly reportExceptionWithCategory:3 name:errorName reason:errorReason callStack:aStackArray extraInfo:info terminateApp:NO];
  35. }
  36. @end