Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect Unexpected Closing of My application

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 ?

like image 350
Saranjith Avatar asked Nov 30 '16 11:11

Saranjith


1 Answers

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.

like image 91
Roee84 Avatar answered Oct 12 '22 22:10

Roee84