I am trying to implement custom completion behavior in a Cocoa application. Normally, when my application exits gracefully, it cleans up the final version database and then exits. This happens inside the AppDelegate (delegate NSApplication) when called [NSApp terminate:aSender]:
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
{
return NSTerminateNow;
}
If an error occurred during execution (for example, the database file was deleted), I present the error to the user and give them the option to Restore (return the file and try again) or exit. If Quit is selected, I want the application to skip database cleanup completely, as this has become impossible. In essence, I would like something like this:
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
{
BOOL gracefulTermination = ...;
if (gracefulTermination == YES)
{
}
return NSTerminateNow;
}
, , gracefulTermination.
NSApp, terminate:, , infoDict, applicationShouldTerminate:?
, ?
, terminate: - , :
[NSApp terminate:self]; foo (a.k.a. self).- NSApp :
[aDelegate applicationShouldTerminate:self]; ( NSApp, foo). - aDelegate
applicationShouldTerminate:, .
foo, , - , , aDelegate , , NSApp . infoDict foo, infoDict, aDelegate, terminate:.
, [NSApp terminate:...] - exit(). , , , Cocoa. , applicationShouldTerminate:, , .