Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

scott455

macrumors member
Original poster
Jun 5, 2022
40
0
xcode 9.x, objective-c method:
Code:
-(void)applicationwillterminate {
   //code to save a file
}
this method is not invoked when closing the app from xcode or any other way.
 

Senor Cuete

macrumors 6502
Nov 9, 2011
424
30
I wrote my own method in my AppController to terminate my program when the user uses the exit menu because I wanted to do some custom stuff:
Code:
- (IBAction) terminateMyApp: (id) sender{
    //NSLog(@"Quitting"); //debugging line
    [NSUserDefaults resetStandardUserDefaults]; //save whatever preferences are currently used
    exit(0);
    //[NSApp terminate: sender]; //standard message tries to save dirty docs, etc.
}
Note that he function exits before the program can invoke [NSApp terminate: sender]; If you include your own implementation of [NSApp terminate: sender] this should override the default implementation and allow you to customize the method. Maybe this will work. Include this method declaration in your Appcontroller and set a break point to see if it's called.
 

Red Menace

macrumors 6502a
May 29, 2011
578
226
Colorado, USA
this method is not invoked when closing the app from xcode or any other way.

Your method does not have the same signature, as shown in the documentation. Method names are case sensitive, and that particular method also has an NSNotification parameter, so it should be:

Objective-C:
- (void)applicationWillTerminate:(NSNotification *)notification
 

Senor Cuete

macrumors 6502
Nov 9, 2011
424
30
Looking at the documentation it looks like your object has to be an NSApplicationDelegate or a sub-class. I assume that this is the case or it wouldn't compile, right?
 

scott455

macrumors member
Original poster
Jun 5, 2022
40
0
used:
Code:
- (void)applicationWillTerminate:(NSNotification *)notification
it still did not respond to the Quit. no notification. I think some link is broken. the code above works perfectly in another project. It does not respond to application finish after launching or similar events.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.