If you want to automatically log out when the application enters the background, try to learn how to delegate the application. For example, there is a method applicationDidEnterBackground , as well as applicationWillTerminate . Here you can log out automatically. If you want to exit the system after the application is in the background for a certain period of time, you need to enable the application to work in the background. To do this, simply go to the application info.plist file and add a new field "Application does not work in the background." Make sure it is not verified. Then, in the applicationDidEnterBackground method, add NSTimer, and after a certain period of time you can exit the system.
source share