Applicationwillterminate: Not Being Called

applicationWillTerminate not getting called on force quit of iOS app

Have you read the documentation for applicationWillTerminate:,

It says,

For applications that do not support background execution or are linked against iOS 3.x or earlier, this method is always called when the user quits the application. For applications that support background execution, this method is generally not called when the user quits the application because the application simply moves to the background in that case. However, this method may be called in situations where the application is running in the background (not suspended) and the system needs to terminate it for some reason.

There is a "maybe" mentioned there. Probably that answers your question. So it is not necessary that this will get called when you quit the app. Probably you might have to use UIApplicationExitsOnSuspend to disable multitasking and then it might get called while putting in background. But that again depends on your app requirement. If you cannot disable multitasking, you might have consider doing that in applicationDidEnterBackground method or so. I am not sure if there are any other delegate methods which will help in identifying the force quit.

applicationWillTerminate not called

I just added

-(BOOL) applicationShouldTerminateAfterLastWindowClosed:(NSApplication *) sender{
return YES;
}

Now applicationWillTerminate invokes

applicationWillTerminate and applicationShouldTerminate don't get run on macOS?

I fixed this by editing Info.plist and setting Application can be killed immediately when user is shutting down or logging out to NO.

screenshot of edited Info.plist

It's pretty weird to me that Xcode autogenerates the method stub for applicationWillTerminate but by default it doesn't work due to this Info.plist key. For future reference, I am running Xcode Version 11.2.1 (11B500).

(Found this answer on the Apple Developer forums.)

applicationWillTerminate does not get invoked

Did you remember to add the handler to the application?

UIApplication *app = [UIApplication sharedApplication];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(applicationWillTerminate:)
name:UIApplicationWillTerminateNotification object:app];


Related Topics



Leave a reply



Submit