CHUncaughtExceptionHandler 1.2.0

CHUncaughtExceptionHandler 1.2.0

Orta Therox 维护。



  • 杨胜浩

CHUncaughtExceptionHandler

CI Status Version License Platform

示例

要运行示例项目,请先克隆仓库,然后从 Example 目录下先运行 pod install

要求

安装

CHUncaughtExceptionHandler 通过 CocoaPods 提供。要安装它,仅需要将以下行添加到您的 Podfile 中

pod 'CHUncaughtExceptionHandler'

使用

OC

#import <CHUncaughtExceptionHandler/CHUncaughtExceptionHandler.h>

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [[CHUncaughtExceptionHandler defaultManager] installUncaughtExceptionHandler:YES];
    return YES;
}

/// log记录
debugLog(@"%@",@"这是一个会被记录的日志");

Swift

CHUncaughtExceptionHandler.defaultManager().installUncaughtExceptionHandler(true)

func debugLog(_ items: Any) {
    debugPrint(items)
    #if DEBUG
        NotificationCenter.default.post(name: NSNotification.Name(rawValue: "saveLog"), object: nil, userInfo: ["log":items])
    #endif
}
因swift无法直接调用OC的宏定义,所以自定义一个方法,实现一样的log记录功能

如果出现崩溃,会发生拦截并进行提示,信号崩溃无法拦截。崩溃信息将被记录在文件中,可以通过 [NSNotificationCenter.defaultCenter postNotificationName:@"checkLog" object:nil]; 唤出日志界面

作者

杨胜浩, [email protected]

许可

CHUncaughtExceptionHandler 在 MIT 许可下可用。更多信息请参阅 LICENSE 文件。