Can we lock the app while app goes to sleep mode in IPhone?

后端 未结 4 1801
孤独总比滥情好
孤独总比滥情好 2021-02-11 10:52

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

相关标签:
4条回答
  • 2021-02-11 11:25

    check in app delegate class there the methods applicationDidEnterForeground and applicationDidEnterBackground are available do your coding there

    0 讨论(0)
  • 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..

    0 讨论(0)
  • 2021-02-11 11:31

    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.

    0 讨论(0)
  • 2021-02-11 11:45

    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.

    0 讨论(0)
提交回复
热议问题