如果应用程序崩溃,如何重置默认亮度?
How to reset default brightness, if application crash?
在我的应用程序中,我试图将全亮度应用于我的视图,并将当前亮度存储在一个变量中,所以一旦我的应用程序状态变为 background/resign-activity 我就重置了默认亮度,现在我的问题是在我的应用程序崩溃的情况下我得到什么事件来重置默认亮度,有任何方法可以调用应用程序崩溃?
提前致谢。
在应用委托中 class 实施
添加一种方法
- (void)applicationWillTerminate:(UIApplication *)application;
{
// Write your code to reset brightness
}
您可以在 main.m 中放置一个 try/catch 块:
int main(int argc, char *argv[]) {
int retVal = 0;
@try {
NSAutoreleasePool *pool = [NSAutoreleasePool new];
retVal = UIApplicationMain(argc, argv, nil, @"NightLightAppDelegate");
[pool release];
} @catch (id any) {
//-- reset brightness
}
return retVal;
}
并在 catch 块中重置亮度。
不过,您还需要重置亮度,以防应用程序终止(实际上并不经常调用)以及进入后台时:
- (void)applicationWillTerminate:(UIApplication *)application {
....
}
-(void) applicationDidEnterBackground:(UIApplication*)application {
...
}
使用
捕获大多数情况
- appWillTerminate
- 异常处理程序
- 信号处理器
在 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
}
在我的应用程序中,我试图将全亮度应用于我的视图,并将当前亮度存储在一个变量中,所以一旦我的应用程序状态变为 background/resign-activity 我就重置了默认亮度,现在我的问题是在我的应用程序崩溃的情况下我得到什么事件来重置默认亮度,有任何方法可以调用应用程序崩溃?
提前致谢。
在应用委托中 class 实施 添加一种方法
- (void)applicationWillTerminate:(UIApplication *)application;
{
// Write your code to reset brightness
}
您可以在 main.m 中放置一个 try/catch 块:
int main(int argc, char *argv[]) {
int retVal = 0;
@try {
NSAutoreleasePool *pool = [NSAutoreleasePool new];
retVal = UIApplicationMain(argc, argv, nil, @"NightLightAppDelegate");
[pool release];
} @catch (id any) {
//-- reset brightness
}
return retVal;
}
并在 catch 块中重置亮度。
不过,您还需要重置亮度,以防应用程序终止(实际上并不经常调用)以及进入后台时:
- (void)applicationWillTerminate:(UIApplication *)application {
....
}
-(void) applicationDidEnterBackground:(UIApplication*)application {
...
}
使用
捕获大多数情况- appWillTerminate
- 异常处理程序
- 信号处理器
在 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
}