IOS capture program crash log, ios capture crash log
It is normal to encounter a program crash during iOS development. How can I capture the exception information and notify developers when the program crashes?
The following describes how to implement it in iOS:
1. Add an exception capture listener when the program starts to handle the callback action when the program crashes.
NSSetUncaughtExceptionHandler (& UncaughtExceptionHandler );
Official documentation: Sets the top-level error-handling function where you can perform last-minute logging before the program terminates.
UncaughtExceptionHandler is a function pointer, which needs to be implemented and can be named as needed. When a program crashes abnormally, the function is called, which is the same as the callback function in C and C ++.
2. Implement your own processing functions
Void UncaughtExceptionHandler (NSException * exception) {NSArray * arr = [exception callStackSymbols]; // obtain the 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: % @ \ n crash reason: % @ \ n call stack info: % @ ", name, reason, arr );}
The above code is very simple, but the function is very big.