I am working an app where lock option is included.My app starts with passcode screen.If I enter correct code then it navigates to next screen.If I dont use the app for long time
check in app delegate class there the methods applicationDidEnterForeground
and applicationDidEnterBackground
are available do your coding there
I have developed same type of apps, where I have implemented this things, For this I made a one Class like this
@interface CommonUIClass:NSObject
+(void)setCurrentViewController:(id)controller;
+(void)openPassWordProtectedScreen;
@end
And
@implementation CommonUIClass
static id currentViewControllerObj;
+(void)setCurrentViewController:(id)controller{
currentViewControllerObj = controller;
}
+(void)openPassWordProtectedScreen{
PROTECTED_CONTROLLER *view = [[PROTECTED_CONTROLLER alloc]init];
if ([currentViewControllerObj respondsToSelector:@selector(presentModalViewController:animated:)]) {
[currentViewControllerObj presentModalViewController:patternLock animated:NO];
}
}
@end
Just import this class to every ViewController And put this code to
-(void)viewWillApear{
[CommonUIClass setCurrentViewController:self];
[super viewWillApear];
}
And When Application Goes in Background
-(void)applicationWillResignActive:(UIApplication *)application{
[CommonUIClass openPassWordProtectedScreen];
}
Thanks..
Yes ofcourse it is possible. You must open the screen in a method called applicationDidBecomeActive
in your Application Delegate. This method is called every time the application is opened from background.
So whenever the user starts the already running app, this method will be called and from this you can first show the Password screen, and after that the respective screen.
You can detect when your app goes to the background using the UIApplicationDidEnterBackgroundNotification
. When it does, record the date and time. When the user opens the app back up, you will receive UIApplicationWillEnterForegroundNotification
. When you receive that, compare the recorded date and time with the current date and time. If that's too old, display the passcode screen.