Exception snapping
1 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. 2 3 工欲善其事, 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. 4 5 before the APPDELEGATE.M class implementation, add:6 7 8 9 voidUncaughtexceptionhandler (NSException *exception) {Ten One //getting exception-related information ANsarray *callstacksymbols =[Exception callstacksymbols]; -NSString *callstacksymbolstr =[Callstacksymbols componentsjoinedbystring:@ - ]; theNSString *reason =[Exception reason]; -NSString *name =[exception name]; - - //Get system Current time +NSDate * Date =[NSDate Date]; -NSDateFormatter * Dateformatter =[[NSDateFormatter alloc] init]; + [dateformatter Setdateformat: @yyyy years mm month DD day HH hours mm minutes ss seconds]; ANSString * Datestr =[Dateformatter stringfromdate:date]; at -NSLog (@ System Current time is:%@ - , datestr); -NSLog (@ exception name:%@ - , name); -NSLog (@ exception Reason:%@ in , reason); -NSLog (@ Stack flag:%@ to , callstacksymbolstr); + } - the * $ Panax Notoginseng Add the following statement to the application startup method implemented by the APPDELEGATE.M class, and set the exception callback function for the system to the above declaration, as described in the "IOS Foundation Framework Overview Document: Constants, data types, frameworks, functions, publishing declarations": - the @implementationappdelegate + A-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchoptions { the +Nssetuncaughtexceptionhandler (&Uncaughtexceptionhandler); -
iOS Development--Error Summary & exception capture