我们可以locking应用程序,而iPhone进入睡眠模式?

我正在工作的应用程序,其中包括locking选项。我的应用程序开始与密码屏幕。如果我input正确的代码,然后导航到下一个屏幕。如果我不使用应用很长时间,它进入睡眠模式。当用户想要现在运行该应用程序,密码屏幕应该出现,用户必须再次input代码。是否有可能?是否有任何教程这个?请不要介意发布相关的代码,如果你已经做了。感谢提前。

是的,当然这是可能的。 您必须在Application Delegate中的一个名为applicationDidBecomeActive的方法中打开屏幕。 每次从后台打开应用程序时,都会调用此方法。

所以每当用户启动已经运行的应用程序,这个方法将被调用,并从这里你可以先显示密码屏幕,然后在相应的屏幕上。

您可以使用UIApplicationDidEnterBackgroundNotification来检测您的应用何时进入背景。 当它的时候,loggingdate和时间。 当用户打开应用程序备份时,您将收到UIApplicationWillEnterForegroundNotification 。 当您收到该信息时,将logging的date和时间与当前date和时间进行比较。 如果这太旧,请显示密码画面。

检查应用程序委托类那里的方法applicationDidEnterForegroundapplicationDidEnterBackground可用做你的代码

我开发了相同types的应用程序,在这里我已经实现了这一点,为此我做了一个这样的类

 @interface CommonUIClass:NSObject +(void)setCurrentViewController:(id)controller; +(void)openPassWordProtectedScreen; @end 

 @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 

只需将此类导入到每个ViewController并将此代码添加到

 -(void)viewWillApear{ [CommonUIClass setCurrentViewController:self]; [super viewWillApear]; } 

当应用程序进入后台

 -(void)applicationWillResignActive:(UIApplication *)application{ [CommonUIClass openPassWordProtectedScreen]; } 

谢谢..