jezzmemo / JJException

Protect the objective-c application(保护App不闪退)
MIT License
1.62k stars 267 forks source link
crash exception-protect hook ios swizzle-method

CocoaPods Compatible Build Status codecov Carthage Compatible Platform License MIT

JJException

Common problems will not crash by the JJException,Hook the Unrecognized Selector,Out of bound,Paramter is nil,etc.Throw the exception to the interface,And then save the exception record to the log,Upgrad the app or Hot-Fix to resolve the exception.

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

如何安装

Requirements

Podfile

pod 'JJException'

Cartfile

github "jezzmemo/JJException"

手动导入代码

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

如何使用

@end

@implementation ViewController

}


## FAQ

> 是否影响上线App Store

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

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

[JJException技术原理](https://github.com/jezzmemo/JJException/blob/master/JJExceptionPrinciple.md)

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

Bugly和友盟是记录Crash Bug的log还有一些统计功能,JJException主要是通过Hook技术来实现,所以不会和JJException冲突

> 如何上传异常信息到Bugly?

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

> Swift是否有作用

是有作用的,Swift有些API实现是独立实现的,比如String,Array,用结构体的方式,但是有些还是沿用了Objective-c,凡是沿用Objective-c的特性的,JJException还是生效的,下面我来列下还依然生效的功能点:

* Unrecognized Selector Sent to Instance
* NSNull
* KVO
* NSNotification
* NSString,NSMutableString,NSAttributedString,NSMutableAttributedString(__注意不是String__)
* NSArray,NSMutableArray,NSDictonary,NSMutableDictionary(__注意不是Array__)

这里贴下Swift的初始化代码示例:
```swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    self.registerJJException()
    return true
}

func registerJJException(){
    JJException.configExceptionCategory(.all)
    JJException.startGuard()
    JJException.register(self);
}

func handleCrashException(_ exceptionMessage: String, extraInfo info: [AnyHashable : Any]?) {

}

JJException Hook那些API?

HookAPI

TODO(大家记得给我星哦)

Linker

License

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