1. Crash may occur in IOS
- Unrecognized selector sent to instance
- Unrecognized selector sent to class
- KVO Crash
- KVC Crash
- NSNotification Crash
- NSTimer Crash
- Container crash (crash caused by collection class operations, such as array out of bounds, inserting nil, etc.)
- Nsstring crash (crash caused by string operation)
- Bad access crash (wild pointer)
- Threading crash (non main thread brushing UI)
- NSNull Crash
2. Common crash
Objective-C
Language is a dynamic language that we can useObjective-C
LanguageRuntime
Runtime mechanism, which is required forHook
Add new classCategory
, in each category+(void)load
; Passed inMethod Swizzling
Intercept the system method that is easy to cause crash, and combine the original system method with the added protection methodSelector (method selector)
AndImp (function implementation pointer)
Swap. Then add protection operation in the replacement method, so as to avoid and repair the crash.
3.KVO Crash
KVO addition times and removal times do not match:
Unregistered observers were removed, resulting in a crash.
Repeatedly remove more times than add, resulting in crash.
Adding multiple times will not crash, but changes will be observed multiple times at the same time.
The observed is released in advance, and the observed still registers KVO during dealloc, resulting in collapse.
For example, if the observed is a local variable (IOS 10 and before will crash).
An observer was added, but the observevalueforkeypath: ofobject: Change: Context: method was not implemented, resulting in a crash.
Keypath = = nil when adding or removing, resulting in a crash.
Article reference:https://www.jianshu.com/p/e3713d309283
4.KVC Crash
There are several reasons for the collapse of KVC in daily use:
Key is not an attribute of the object, causing a crash.
The keypath is incorrect, causing a crash.
The key is nil, causing a crash.
Value is nil, which sets a value for a non object, causing a crash.