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

标签 ios objective-c iphone

在我的应用程序中,我试图将完整亮度应用于我的 View ,并将当前亮度存储在一个变量中,因此一旦我的应用程序状态变为背景/退出事件,我就会重置默认亮度,现在我的问题是我的应用程序崩溃的情况我可以重置默认亮度,有什么方法可以在应用程序崩溃时调用?

提前致谢。

最佳答案

使用捕获大多数情况

  1. 应用程序将终止
  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);

那么你就有了

- (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
}

关于ios - 如果应用程序崩溃,如何重置默认亮度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27981409/

相关文章:

iphone - Quartz Core、Core Graphics 和 Quartz 2D 之间有什么区别?

ios - 在 iOS 中解密加密文件 (AES CFB8)

iOS SecTrustRef 始终为 NULL

iphone - UITableView 没有滚动到底部

iphone - 将单元格的重新排序属性设置为 NO

objective-c - NSMutableArray 使用选择器排序

iphone - 如何从 uitableview 中选择值并将其显示在上一页的按钮上

ios - 标签栏 Controller 需要点击2次返回主视图

ios - iOS 版 Swift : change array order and populate Picker

ios - 如何使用 Typhoon 为集成测试注入(inject)假的、 stub 的或模拟的依赖项