Saranjith Saranjith - 3 days ago 5
Objective-C Question

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.

Answer

To save data of user before app gets terminated, the appropriate method for that is UIApplication class method applicationWillTerminate:

- (void)applicationWillTerminate:(UIApplication *)application

Like,

- (void)applicationWillTerminate:(UIApplication *)application
{
    // Called when the application is about to terminate. Save related data here. See also applicationDidEnterBackground:.

    //write code to save user data, app will terminate
}
Comments