Collin Zhang
Collin Zhang

Reputation: 513

What will happen to my code when I force quit an iOS app?

I am developing an iOS app. I am wondering what will happen to my code if the app is force quit. Will the current code been executed before the app is terminated or will it be stopped at once? Do I need to make my app robust enough that whenever the user force quit the app, it will never crush in future?

Upvotes: 1

Views: 348

Answers (1)

Nimesh Neema
Nimesh Neema

Reputation: 2013

UIApplicationDelegate method applicationWillTerminate(_:) will be called which gives you the opportunity to run code.

From the applicationWillTerminate(_:) - UIApplicationDelegate documentation:

This method lets your app know that it is about to be terminated and purged from memory entirely. You should use this method to perform any final clean-up tasks for your app, such as freeing shared resources, saving user data, and invalidating timers. Your implementation of this method has approximately five seconds to perform any tasks and return. If the method does not return before time expires, the system may kill the process altogether.

Your app is given an opportunity to save/cleanup before it is purged, and your method gets five seconds to run before the process is terminated by the operating system.

Upvotes: 1

Related Questions