JJException:保護 App 不閃退
JJException
保護App,一般常見的問題不會導致閃退,增強App的健壯性,同時會將錯誤丟擲來,根據每個App自身的日誌渠道記錄,下次迭代或者熱修復以下問題.
-
Unrecognized Selector Sent to Instance
-
NSArray,NSMutableArray,NSDictonary,NSMutableDictionary
-
KVO
-
Zombie Pointer
-
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的實現技術原理是什麼?
ofollow,noindex" target="_blank">JJException技術原理
JJException是否和Bugly和友盟等第三方庫是否有衝突?
Bugly和友盟是記錄Crash Bug的log還有一些統計功能,JJException主要是通過Hook技術來實現,所以不會和JJException衝突,只有一種情況會有衝突,第三方庫和JJException,Hook同樣的方法,可能導致JJException不起作用
如何上傳異常資訊到Bugly?
Bugly可以幫我們解決重複資訊和CallStack資訊,以及狀態維護。
實現JJExceptionHandle協議後,將異常資訊組織成Error,然後用[Bugly reportError:error]上傳異常資訊,上傳後異常資訊Bugly的後臺錯誤分析
選單裡
TODO(大家記得給我星哦)
- 增強Hook的健壯性
- 支援多平臺(Mac OS X,TVOS,WatchOS)
License
JJException is released under the MIT license. See LICENSE for details.