How to implement custom NSApplication terminate: behavior in Cocoa? -
I am trying to implement the custom completion behavior in the Cocoa application. Generally when my app gets streamlined, it cleans up the last-runtime database and then exits. This is within the appless gadget (representative of NSApplication
) whenever is called [NSApp termination: acedor]
:
- (NSApplicationTerminateReply) ApplicationShouldTerminate :( NSApplication *) Sender {// database cleaning ... back NSTerminateNow; }
If an error occurs during the runtime (for example the database file was deleted), then I present the error to the user, and the option to recover them I am (put the file back and try again), or if the selection has to be done to quit, I would like to quit the applet, because it is no longer possible because database cleaning is completely Ending with. In essence, I want something like this:
- (NSApplicationTerminateReply) applicationShouldTerminate: (NSApplication *) Sender {BOOL gracefulTermination = ...; If (Grace == Yes) {// Database Cleanup ....} Return NSTerminateNow; }
The problem is, of course, getting value for grace .
Does the custom variable end in NSAP
when the ends:
is called as an information, and then the ApplicationShouldTerminate:
?
Is there a better way to complete a custom completion behavior?
As far as I know, when ends:
is said by another object, this happens:
[NSAPP termination: Self];
is called Foo (aka self ). [aDelegate applicationShouldTerminate: self];
( itself is NSApp, not foo ). applicationShouldTerminate:
. foo disappears somewhere, and by the time the aDelegate message is received, it has gone for good And appears as the only NSApp
sender, it lets me stop the custom data code, including the custom finished:
behavior.
I know that it is possible to get it out without using exit () with something like [NSAPP termination: ...]
without using / Code>. Although I have read it, but it has been dropped down due to not being kosher for cocoa. Apart from this, it will also prevent any other cleaning work from being within the
application: Principle:
, operations should also be left without any pseudo-exhaust.
The ideal solution would be to configure your app in a way that the app representative can tell that Whether it is allowed to end or not?
Assuming your application representative is not able to access this information in any other way (it is to say that, the object that is triggered can affect or not). It seems like a simple solution: the subclass NSApplication, the terminationInfo
property and the override end:
to set this property and make a super call.
Comments
Post a Comment