GithubHelp home page GithubHelp logo

evilino / jjexception Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jezzmemo/jjexception

0.0 2.0 0.0 3.61 MB

Protect the objective-c application(保护App不闪退)

License: MIT License

Ruby 8.29% Objective-C 91.71%

jjexception's Introduction

CocoaPods Compatible Build Status codecov Carthage Compatible Platform License MIT

JJException

保护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{

}

问题答疑

是否影响上线App Store

不会的,JJException的功能都是使用的官方API,没有任何私有API

保护App的实现技术原理是什么?

JJException技术原理

JJException是否和Bugly和友盟等第三方库是否有冲突?

Bugly和友盟是记录Crash Bug的log还有一些统计功能,JJException主要是通过Hook技术来实现,所以不会和JJException冲突,只有一种情况会有冲突,第三方库和JJException,Hook同样的方法,可能导致JJException不起作用

如何上传异常信息到Bugly?

Bugly可以帮我们解决重复信息和CallStack信息,以及状态维护。
实现JJExceptionHandle协议后,将异常信息组织成Error,然后用[Bugly reportError:error]上传异常信息,上传后异常信息Bugly的后台错误分析菜单里

TODO(大家记得给我星哦)

  • 增强Hook的健壮性

License

JJException is released under the MIT license. See LICENSE for details.

jjexception's People

Contributors

jezzmemo avatar

Watchers

veen avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.