欢迎光临
我们一直在努力

JJException 0.0.9发布(保护App不闪退)

建站超值云服务器,限时71元/月

JJException 0.0.9发布(保护App不闪退)

项目介绍:

保护App,一般常见的问题不会导致闪退,增强App的健壮性,同时会将错误抛出来,根据每个App自身的日志渠道记录,下次迭代或者热修复以下问题.

  • Unrecognized Selector Sent to Instance

  • NSArray,NSMutableArray,NSDictonary,NSMutableDictionary

  • KVO

  • Zombie Pointer

  • NSTimer

  • NSNotification

  • NSString,NSMutableString,NSAttributedString,NSMutableAttributedString

如何安装

Podfile

pod 'JJException'

Cartfile

github "jezzmemo/JJException"

手动导入代码

导入Source文件夹里所有文件,需要将MRC目录下所有.m文件,编译选项更改成-fno-objc-arc

如何使用

  • 所有异常的分类,根据自身需要,自由组合

typedef NS_OPTIONS(NSInteger,JJExceptionGuardCategory){
    JJExceptionGuardNone = 0,
    JJExceptionGuardUnrecognizedSelector = 1 << 1,
    JJExceptionGuardDictionaryContainer = 1 << 2,
    JJExceptionGuardArrayContainer = 1 << 3,
    JJExceptionGuardZombie = 1 << 4,
    JJExceptionGuardKVOCrash = 1 << 5,
    JJExceptionGuardNSTimer = 1 << 6,
    JJExceptionGuardNSNotificationCenter = 1 << 7,
    JJExceptionGuardNSStringContainer = 1 << 8,
    JJExceptionGuardAllExceptZombie = JJExceptionGuardUnrecognizedSelector | JJExceptionGuardDictionaryContainer | JJExceptionGuardArrayContainer | JJExceptionGuardKVOCrash | JJExceptionGuardNSTimer | JJExceptionGuardNSNotificationCenter | JJExceptionGuardNSStringContainer,
    JJExceptionGuardAll = JJExceptionGuardUnrecognizedSelector | JJExceptionGuardDictionaryContainer | JJExceptionGuardArrayContainer | JJExceptionGuardZombie | JJExceptionGuardKVOCrash | JJExceptionGuardNSTimer | JJExceptionGuardNSNotificationCenter | JJExceptionGuardNSStringContainer,
};
  • 设置异常类型并开启

    [JJException configExceptionCategory:JJExceptionGuardAll];
    [JJException startGuardException];
  • 实时关闭保护

    [JJException stopGuardException];
  • 当异常时,默认程序不会中断,如果需要遇到异常时退出,需要如下设置:

    //Default value:NO
    JJException.exceptionWhenTerminate = YES;
  • Zombie使用黑名单机制,只有加入这个名单的才有作用,示例如下:

    [JJException addZombieObjectArray:@[TestZombie.class]];
  • 如果需要记录日志,只需要实现JJExceptionHandle协议,并注册:

@interface ViewController ()<JJExceptionHandle>

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [JJException registerExceptionHandle:self];
}

- (void)handleCrashException:(NSString*)exceptionMessage exceptionCategory:(JJExceptionGuardCategory)exceptionCategory extraInfo:(nullable NSDictionary*)info{

}

https://github.com/jezzmemo/JJException

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » JJException 0.0.9发布(保护App不闪退)
分享到: 更多 (0)