From other threads here I have gotten a modal view “login screen” to show whenever my app starts for the first time. What I want now is to have the login screen show whenever the app is brought back into the foreground (i.e. its running in the background and is brought up again) so the user can log back in.
Here’s my code from the applicationDidFinishLaunchingWithOptions
LoginViewController *loginViewController = [[LoginViewController alloc] initWithNibName:@"LoginView" bundle:nil];
if (lockScreenOnOff)
{
[self.tabBarController presentModalViewController:loginViewController animated:YES];
[self.window makeKeyAndVisible];
}
where the modal login view is shown if a switch (lockScreenOnOff) is on. How can I accomplish this?
Implement
applicationDidEnterBackground:andapplicationDidBecomeActive:in your application delegate. (UIApplicationDelegate class reference)Additionally you can also use NSTimer to invalidate a session after a certain amount of time.