Sometimes user presses the home button and close the application from recent list.
I want to warn user with a message like "This application not properly closed last time
".
How to detect such unexpected closing of application? Is there any way to do it? Also i would like to save the data filled by user.
The below method works good but after staying in background for a while and closing the application will not get invoked to this method.
- (void)applicationWillTerminate:(UIApplication *)application
Is there any solution in swift 3.0 ?
To save the data filled by the user, you should use the func applicationDidEnterBackground(_ application: UIApplication)
function.
This is the function description:
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
As for "This application not properly closed last time" message you want to present the user - it's wrong to show such a message. The way to close the app is to press the home screen and close it from the list, so this is the expected behavior.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With