I’m having a problem with applicationShouldTerminate.
What ever I do it seams that has no effect. Any help would be appreciated.
I’m well versed in programing but this just gives me headache. Im going over some basic tutorials for xcode , as I’m new to mac in general, and am currently looking at a simple flashlight app.
It exists but I would like to add a alert box here with option not to quit.
(void)applicationWillTerminate:(UIApplication *)application { [application setIdleTimerDisabled:NO]; }
this has no effect, alert is closed even before its created.
(void)applicationWillTerminate:(UIApplication *)application { [application setIdleTimerDisabled:NO]; UIAlertView *alertTest = [[UIAlertView alloc] initWithTitle:@'This is a Test' message:@'This is the message contained with a UIAlertView' delegate:self cancelButtonTitle:@'Button #1' otherButtonTitles:nil]; [alertTest addButtonWithTitle:@'Button #2']; [alertTest show]; [alertTest autorelease]; NSLog(@'Termination'); }
I did some reading online and found that it should be possible to do this with
(NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*)sender
But no mater where I put that declaration I get error: syntax error before NSApplicationTerminateReply.
There is no syntax error except that xcode seems not to recognize NSApplicationTerminateReply as valid input.
Any sample code would be greatly appreciated.
applicationShouldTerminate and NSApplication do not exist on the iPhone. You have to use UIApplication.
The alert view is never shown because the ‘show’ method does not block, and therefore, the end of ‘applicationWillTerminate’ is reached immediately after you create the alert view and try to show it. I believe this is by design. You can’t really begin asynchronous operations in ‘applicationWillTerminate’.