IOS capture program crash log
We often encounter a crash when running an APP on an iPhone or iPad tablet. Sometimes an APP is turned on, but it suddenly crashes. This is definitely a headache for developers. So how can I get the iOS device crash log? This provides some simple methods for developers to communicate with users.
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.
The Code is as follows:
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
The Code is as follows:
Void UncaughtExceptionHandler (NSException * exception ){
NSArray * arr = [exception callStackSymbols]; // obtain the current call stack information
NSString * reason = [exception reason]; // the cause of the crash is very important.
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.
The above is all the content of this article. I hope it will be helpful for you to learn about IOS development.