在我的应用程序中,我试图将全亮度应用到我的视图中,并将当前亮度存储在一个变量中,因此只要我的应用程序状态变为后台/ resign-activity,我就会重置默认亮度,现在我的问题是我的应用程序崩溃的情况我重置默认亮度的事件是什么,有什么方法可以调用应用程序崩溃?
提前致谢。
答案 0 :(得分:7)
使用
捕获大多数情况在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
}
答案 1 :(得分:3)
你可以在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 {
...
}
答案 2 :(得分:0)
在app委托类实现中 添加一个方法
- (void)applicationWillTerminate:(UIApplication *)application;
{
// Write your code to reset brightness
}