We are often confronted with the problem of running apps on the iphone or on the ipad tablet, sometimes opening an app and then "flashing back". For developers, this is definitely a headache. So how do I get to the iOS device crash log? This provides some simple ways for developers to communicate with users.
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
The code is 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
The code is 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:%@ n 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.