iOS crashes, program kill processing

Recently, I need a function to save drafts when the program exits unexpectedly, so I have studied the processing of program flashback and killing.


1. The program was killed manually

- (void)applicationWillTerminate:(UIApplication *)application{

/// Handle the event

}


2. The program crashes and crashes

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

 //  catch program crash

    NSSetUncaughtExceptionHandler(&UncaughtExceptionHandler);

}

void UncaughtExceptionHandler(NSException *exception) {

// NSArray *arr = [exception callStackSymbols];// Get current call stack information

// NSString *reason = [exception reason];// Very important, it is the reason for the crash

// NSString *name = [exception name];// Exception type

}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325388849&siteId=291194637