Skip to content

hydreamit/HyCrashHook

Repository files navigation

HyCrashHook

Hook 常见Crash不让程序闪退, 订阅Crash根据自身需要做相应处理。


Hook Classes
NSObject (KVC、KVO、UnrecognizedSelector)
NSArray、NSMutableArray
NSDictionary、NSMutableDictionary
NSString、NSMutableString
NSAttributedString、NSMutableAttributedString
NSSet、NSMutableSet
NSOrderedSet 、NSMutableOrderedSet
NSNotificationCenter
NSDecimalNumber
NSUserDefaults
CADisplayLink
NSTimer
NSCache
NSData

如何导入

Podfile

pod 'HyCrashHook'

手动导入

直接将HyCrashHook文件夹拖入项目,然后把NSMutableArray+CrashHook.m文件的编译选项添加-fno-objc-arc

如何使用

  • 开启需要Hook的类
    // 开启Hook所有支持的类
    [HyCrashHookManager openCrashHookWithClasses:nil];
    
    // 开启Hook指定的类
    [HyCrashHookManager openCrashHookWithClasses:@[NSDictionary.class, NSMutableDictionary.class]];
  • 订阅Hook类的Crash
    // 订阅所有已开启Hook类的Crash
    [HyCrashHookManager subscribeCrashWithClasses:nil
                                            block:^(__unsafe_unretained Class cls,
                                                    NSString *location,
                                                    NSString *description,
                                                    NSArray<NSString *> *callStack) {

         // handle hooked crash
        // ....
    }];
    
    // 订阅指定已开启Hook类的Crash
    HyCrashHandler *crashHandler =
    [HyCrashHookManager subscribeCrashWithClasses:@[NSDictionary.class, NSMutableDictionary.class]
                                            block:^(__unsafe_unretained Class cls,
                                                    NSString *location,
                                                    NSString *description,
                                                    NSArray<NSString *> *callStack) {
    
         // handle hooked crash
        // ....
    }];
    
    // 取消某个订阅
    [HyCrashHookManager disposeCrashHandler:crashHandler];
  • 开启关闭Crash日志打印
    // 开启Crash日志打印
    [HyCrashHookManager openCrashHookLog];

    // 关闭Crash日志打印
    [HyCrashHookManager closeCrashHookLog];

About

Hook crash keep app running safely.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published