having same issue, need to do some cleanup when mac app is closed, saw this hint on a stack overflow post
https://stackoverflow.com/questions/8193305/applicationwillterminate-not-called
add this function to the mac app delegate, and then the applicationWillTerminate: method is called
-(BOOL) applicationShouldTerminateAfterLastWindowClosed:(NSApplication *) sender{
return YES;
}
i havent tested all cases e.g. user kills an app with kill -9 or something like that, i just checked the window close case at this point
(you may need to set both of the aforementioned info plist values in the other chat responses here to NO. I have them set to NO.
i did not go thru testing iterations with those plist values. one or both may not be needed.) see attached screenshot for plist settings i used.
Update: If you use normal quit from Activity Monitor, this solution traps the exit. If you use force quit, it does not (which kind of makes sense). (That may be the kill -9).
also, an app crash doesnt seem to trigger the WillTerminate
test:
// at end of did finish launching:
[self performSelector:@selector(forceCrash) withObject:nil afterDelay:10];
-(void)forceCrash {
int *x = NULL;
int y = *x;
}
so, at least normal app close is handled