Saranjith Saranjith - 8 months ago 40
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 Source

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

- (void)applicationWillTerminate:(UIApplication *)application


- (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