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
.
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
Simple Low-Latency Audio Playback in iOS Swift
Invalid Image Path - No Image Found at the Path. Cfbundleicons Xcode 5
How to Execute Some Code After a Segue Is Done
Uisearchcontroller Persisting After Segue
Why Would a 'Scheduledtimer' Fire Properly When Setup Outside a Block, But Not Within a Block
Determine User's "Temperature Unit" Setting on iOS 10 (Celsius/Fahrenheit)
Differentiate Between Screen Lock and Home Button Press on iOS7
How to Disable iPhone 6 Native Resolution
Swift iOS9 New Contacts Framework - How to Retrieve Only Cncontact That Has a Valid Email Address
Get Error Code -11843 While Exporting Mp3 File in Ipod Library Since iOS 5.1
Deferredlocationupdatesavailable Returns No in iOS 10
Uisearchdisplaycontroller Without Dimming
Get Dns Server Ip from iPhone Settings
Region Monitoring Glitch on iOS 7 - Multiple Notifications at the Same Time
Search Bar and Search Display Controller in Table View
Adding Unlimited Lines in a Text (Swiftui)
Urlresponse Is Not Retrieved After Storing in Cache Using Storecachedresponse