ios防crash崩溃--------LSSafeProtector

LSSafeProtector 是一个可快速集成但功能强大的防止crash库,不改变原代码支持KVO自释放,可以检测到dealloc时未释放的kvo,等19种crash,使用Objective-C编写.可以让程序出现异常的时候不闪退,提高程序的健壮性。

推荐使用 CocoaPods 安装。

  1. 在 Podfile 中添加 pod 'LSSafeProtector'
  2. 执行 pod install 或 pod update。(如搜索不到,请更新pod仓库pod repo update)
  3. 导入 "LSSafeProtector.h"
  4. 通过如下方式开启防止闪退功能,debug模式会打印crash日志,同时会利用断言来让程序闪退,也会回调block,达到测试环境及时发现及时修改,Release模式既不打印也不会断言闪退,会回调block,自己可以上传exception到bugly(注意线上环境isDebug一定要设置为NO)
  5. //注意线上环境isDebug一定要设置为NO)

        [LSSafeProtector openSafeProtectorWithIsDebug:NO block:^(NSException *exception, LSSafeProtectorCrashType crashType) {

            //[Bugly reportException:exception];

            //此方法相对于上面的方法,好处在于bugly后台查看bug崩溃位置时,不用点击跟踪数据,再点击crash_attach.log,查看里面的额外信息来查看崩溃位置

            [Bugly reportExceptionWithCategory:3 name:exception.name reason:[NSString stringWithFormat:@"%@  崩溃位置:%@",exception.reason,exception.userInfo[@"location"]] callStack:@[exception.userInfo[@"callStackSymbols"]] extraInfo:exception.userInfo terminateApp:NO];

        }];

        //打开KVO添加,移除的日志信息

        [LSSafeProtector setLogEnable:YES];

  6. 二当没有使用这个框架的时候程序崩溃

  7. 当使用框架以后

猜你喜欢

转载自blog.csdn.net/a18339063397/article/details/84971830
今日推荐