# ZXAvoidCrash **Repository Path**: zj1208/ZXAvoidCrash ## Basic Information - **Project Name**: ZXAvoidCrash - **Description**: 防崩溃工具,可以预防NSNull对象、Obejective-C常用对象(NSArray/NSMutableArray,NSString/NSMutableString,NSAttributeString/NSMutableAttributeString,NSDictionary/NSMutableDictionary,NSSet/NSMutableSet,NSIndexSet)、KVC的调用崩溃。 - **Primary Language**: Objective-C - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2022-11-11 - **Last Updated**: 2024-07-01 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## 简介: 防崩溃工具,可以预防NSNull对象、Obejective-C常用对象(NSArray/NSMutableArray,NSString/NSMutableString,NSAttributeString/NSMutableAttributeString,NSDictionary/NSMutableDictionary,NSSet/NSMutableSet,NSIndexSet)、KVC的调用方法崩溃。如果拦截到NSException则发送一个包括堆栈的异常信息的通知。 NSNull对象: 在请求服务端数据返回对象的时候,如果对它调用方法发送消息会发生崩溃,会有如下信息-[NSNull objectForKey:]: unrecognized selector sent to instance 0x7fff8a6d5fa0。使用本工具处理之后,对象对未识别的消息会返回nil,不会崩溃。简化NullSafe,只处理JSON和Plist值。 Obejective-C常用对象: 包括NSArray/NSMutableArray,NSString/NSMutableString,NSAttributeString/NSMutableAttributeString,NSDictionary/NSMutableDictionary,NSSet/NSMutableSet,NSIndexSet。 KVC: 对setValueForKey:,valueForKey做处理。 原理: 如果向NSNull对象发送对象无法处理的消息,在完成消息转发流程后会崩溃。我们在间接消息转发的函数中,自己生成一个方法签名,然后把invocation调用给nil对象就不会崩溃了。 ![输入图片说明](Example/CAIAvoidCrash/Images.xcassets/1.png) ![输入图片说明](Example/CAIAvoidCrash/Images.xcassets/1.5.png) ![输入图片说明](Example/CAIAvoidCrash/Images.xcassets/2.png) ## Installation ```ruby pod 'CAIAvoidCrash' ``` ## Author 海参, 879654715@qq.com ## License CAIAvoidCrash is available under the MIT license. See the LICENSE file for more info. ## Push命令 pod repo push aliyun-caihuasuan-specrepository /Users/simon/CAIAvoidCrash/CAIAvoidCrash.podspec --allow-warnings --verbose $ pod lib lint --allow-warnings --no-clean $ pod repo push gitee-zj1208-specs ZXAvoidCrash.podspec --allow-warnings --verbose ## 更新记录 V0.1.2 2022.11.10 1.null安全,对象对未识别的消息返回nil。简化NullSafe,只处理JSON和Plist值。 V0.1.4 2023.03.14 1. 增加NSDictionary和NSMutableDictionary崩溃处理防护。 2.增加崩溃上报类ZXAvoidCrashReport,统一处理; V0.1.5 2023.03.24 1. 增加崩溃处理防护:NSSet、NSMutableSet、NSCountedSet、NSIndexSet、NSMutableIndexSet。 V0.1.6 2023.03.30 1. 增加崩溃处理防护:NSString 70%、NSMutableString。 V0.1.7 2023.06.20 1. runtime的hook方法修改;交换类方法实现之前有bug; V0.1.8 2023.09.01 1. 修复字典防崩溃bug,返回值没返回的问题; 2. 添加通知上报异常字典 3. 增加demo列表 V0.1.9 2023.09.05 1. 增加demo列表 2. 增加KVC防崩溃