ApplicationWillTerminate is not called

I want to save my data before completion, so the AppControll class conforms to the NSApplicationDelegate protocol and declares a method; and in the interface builder, I linked the output of the window delegate to the AppController, but I cannot get the method called.

Where am I mistaken, what should I do?

+1
objective-c cocoa macos
Dec 01 '10 at 1:55
source share
4 answers

Did you remember adding a handler to the application?

 UIApplication *app = [UIApplication sharedApplication]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillTerminate:) name:UIApplicationWillTerminateNotification object:app]; 
+4
Dec 01 '10 at 2:01
source share

Are you ending the application with Xcode? Alternatively, unexpected termination is included in your Info.plist?

Any of them will cause the SIGTERM signal to be sent to the application, immediately terminating it, without the possibility of an NSApplication instance, sending the applicationWillTerminate: message to its delegate. (This is the point of abrupt termination: your application dies instantly. You can disable it programmatically if it is bad.)

Try abandoning your application within yourself (the "Exit" menu item in the "Application" menu) or using the Dock to exit it (right-click on your application bar and select "Quit"). While abrupt termination is disabled (or has never been enabled), any of these will cause your application object to send an applicationWillTerminate: message.

Also, make sure your delegate sends other application delegate messages, such as applicationWillFinishLaunching: and make sure you plug the socket in the correct tip (your MainMenu nib).

+6
Dec 01 '10 at 3:50
source share

Is multitasking enabled? This can be a problem - pressing the home button does not call applicationWillTerminate: if the application goes into the background.

+2
Dec 01 2018-10-12T00:
source share

In applicationWillFinishLaunching: add:

 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillTerminate:) name:UIApplicationWillTerminateNotification object:nil]; 
0
Feb 09 '15 at 5:42
source share



All Articles