在我的应用程序中,我试图将完整亮度应用于我的 View ,并将当前亮度存储在一个变量中,因此一旦我的应用程序状态变为背景/退出事件,我就会重置默认亮度,现在我的问题是我的应用程序崩溃的情况我可以重置默认亮度,有什么方法可以在应用程序崩溃时调用?
提前致谢。
最佳答案
使用捕获大多数情况
- 应用程序将终止
- 异常处理程序
- 信号处理程序
在 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/