如果应用程序崩溃,如何重置默认亮度?

Dip*_*ama 1 iphone objective-c ios

在我的应用程序中,我试图将全亮度应用到我的视图中,并将当前亮度存储在一个变量中,因此一旦我的应用程序状态变为后台/ resign-activity,我就会重置默认亮度,现在我的问题是,如果是我的应用程序崩溃我重置默认亮度的事件是什么,有任何方法在应用程序崩溃时调用?

提前致谢.

Dai*_*jan 7

大多数情况下使用

  1. appWillTerminate
  2. 异常处理程序
  3. 信号处理器

在didFinishLaunching期间安装所需的处理程序

// installs HandleExceptions as the Uncaught Exception Handler
NSSetUncaughtExceptionHandler(&HandleExceptions);
// create the signal action structure
struct sigaction newSignalAction;
// initialize the signal action structure
memset(&newSignalAction, 0, sizeof(newSignalAction));
// set SignalHandler as the handler in the signal action structure
newSignalAction.sa_handler = &SignalHandler;
// set SignalHandler as the handlers for SIGABRT, SIGILL and SIGBUS
sigaction(SIGABRT, &newSignalAction, NULL);
sigaction(SIGILL, &newSignalAction, NULL);
sigaction(SIGBUS, &newSignalAction, NULL);
Run Code Online (Sandbox Code Playgroud)

那你有

- (void)applicationWillTerminate:(UIApplication *)application {
  // Write your code to reset brightness
}

void HandleExceptions(NSException *exception) {
    DebugLog(@"This is where we save the application data during a exception");
    // Save application data on crash
  // Write your code to reset brightness
}

void SignalHandler(int sig) {
    DebugLog(@"This is where we save the application data during a signal");
    // Save application data on crash
  // Write your code to reset brightness
}
Run Code Online (Sandbox Code Playgroud)