IOS captures out-of-system exceptions
The beautiful Life of the Sun Vulcan (http://blog.csdn.net/opengl_es)
This article follows "Attribution-non-commercial use-consistent" authoring public agreement
Reprint Please keep this sentence: Sun Vulcan's Beautiful Life-this blog focuses on Agile development and mobile and IoT device research: IOS, Android, HTML5, Arduino, Pcduino , Otherwise, the article from this blog refused to reprint or re-reproduced, thank you for your cooperation.
Sometimes the application crashes, and the log output information is too small to locate the problem, this is the most headache, especially when it is very tired, has not been able to remember what has just changed, this is called non-resistance.
工欲善其事, its prerequisite, the following method can give more information, let you see the sequence of stack execution, where the collapse, you can probably give a thought to determine the crux of the problem.
Before the APPDELEGATE.M class implementation, add:
void Uncaughtexceptionhandler (NSException *exception) { //Get exception related information Nsarray *callstacksymbols = [exception Callstacksymbols]; NSString *callstacksymbolstr = [Callstacksymbols componentsjoinedbystring:@ "\ n"]; NSString *reason = [exception reason]; NSString *name = [exception name]; Gets the current time of the system nsdate * date = [NSDate date]; NSDateFormatter * Dateformatter = [[NSDateFormatter alloc] init]; [Dateformatter setdateformat:@ "yyyy mm month DD day HH hours mm minutes ss seconds"]; NSString * Datestr = [dateformatter stringfromdate:date]; NSLog (@ "System current time:%@ \ n", datestr); NSLog (@ "exception name:%@ \ n", name); NSLog (@ "Exception reason:%@ \ n", reason); NSLog (@ "stack flag:%@ \ n", callstacksymbolstr);}
In the APPDELEGATE.M class implementation of the application startup method, add the following statement, the system set the exception callback function for the above declaration, detailed description See "IOS Foundation Framework Overview Documentation: constants, data types, frames, functions, publishing declarations":
@implementation appdelegate-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: ( Nsdictionary *) launchoptions { nssetuncaughtexceptionhandler (&uncaughtexceptionhandler);