It is normal to encounter a program crash in iOS development, how to catch exception information when a program crashes and notify the developer?
Here's how to implement this in iOS:
1. Add an exception capture listener at the start of the program to handle the callback action when the program crashes
Copy Code code as follows:
Nssetuncaughtexceptionhandler (&uncaughtexceptionhandler);
Official Document Description: Sets the top-level error-handling function where you can perform last-minute logging the program before.
Uncaughtexceptionhandler is a function pointer that needs to be implemented to get the name we want. When a program crashes abnormally, the function gets called, which is the same as the concept of a callback function in c,c++.
2. Implement your own processing functions
Copy Code code as follows:
void Uncaughtexceptionhandler (NSException *exception) {
Nsarray *arr = [exception callstacksymbols];//get current call stack information
NSString *reason = [Exception reason];//very important, is the cause of the crash
NSString *name = [Exception name];//exception type
NSLog (@ "Exception type:%@ \ Crash reason:%@ \ n Call stack info:%@", name, Reason, arr);
}
The above code is very simple, but the effect is very large.
The above is the entire content of this article, I hope to learn about the development of iOS can help.