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-CLanguage is a dynamic language that we can use
RuntimeRuntime mechanism, which is required for
HookAdd new class
Category, in each category
+(void)load; Passed in
Method SwizzlingIntercept the system method that is easy to cause crash, and combine the original system method with the added protection method
Selector (method selector)And
Imp (function implementation pointer)Swap. Then add protection operation in the replacement method, so as to avoid and repair the 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.
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.