You can write a class crashpolictioincatcher and define a static method startCrashExceptionCatch in the class. In the method, call NSSetUncaughtExceptionHandler (& uncaughtExceptionHandler );
Bind the void uncaughtExceptionHandler (NSException * exception) method to handle exception information. Print the exception in void uncaughtExceptionHandler (NSException * exception) and submit the device information to the server, in this way, exception information can be effectively collected during testing.
Header file
#import
@interface CrashExceptioinCatcher : NSObject+ (void)startCrashExceptionCatch;@end
Implementation File
# Import "crashpolictioincatcher. h "// submit the exception Log information void uncaughtExceptionHandler (NSException * exception) {// The exception Log information NSString * logInfo = [NSString stringWithFormat: @" Crash: \ n % @ \ nStack Trace: \ n % @ \ n ", [exception description], [exception callStackSymbols]; NSLog (@" % @ ", logInfo ); // TODO: Submit to the server for collection //....} @ implementation CrashExceptioinCatcher + (void) startCrashExceptionCatch {// Sets the top-level error-handling function where you can perform last-minute logging before the program terminates. NSSetUncaughtExceptionHandler (& uncaughtExceptionHandler); // sets the exception Log information processing} @ end
Usage:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ [CrashExceptioinCatcher startCrashExceptionCatch]; // ................. }
Reference: http://arthurchen.blog.51cto.com/2483760/734175