Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 980005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:18:37+00:00 2026-05-16T04:18:37+00:00

Before iOS4, my app’s initial view controller would check a passcode on/off settings variable

  • 0

Before iOS4, my app’s initial view controller would check a passcode on/off settings variable in viewWillAppear and if set on, present a modal passcode screen that would stay there until the correct passcode was entered or the Home button was pressed.

With iOS4, if my app has been in the background, I would like the user to feel comfortable that the data contained within the app is not easily accessible if they were to hand their phone to someone to use.

Since the app could return to any screen (the screen that the app was last on), I figured I would use the UIApplicationWillEnterForegroundNotification all over the place with local selectors (duplicate enterPasscode methods), each having the correct view controller to push based on the local screen, but there has to be a better way.

I may be having a slight conceptual misunderstanding here. Can someone suggest another approach or nudge me along to the next step. Can I have this as a shared method but still know the correct local view controller to push?

Thanks

EDIT/UPDATE:

Short version: It works, but may there still may be a better way (any help appreciated)…

I created a standard singleton with a view controller.

PasscodeView.h containing:

UIViewController *viewController;
@property (nonatomic, retain) UIViewController *viewController;

PasscodeView.m containing:

@synthesize viewController;

I put this in the AppDelegate:

-(void)applicationWillEnterForeground:(UIApplication*)application {

    PasscodeView *passcodeView = [PasscodeView sharedDataManager];
    UIViewController *currentController =  [passcodeView viewController];
    NSLog(@"%@", currentController);  //testing
    EnterPasscode *passcodeInput = [[EnterPasscode alloc] initWithNibName:@"Passcode" bundle:nil];
    [currentController presentModalViewController:passcodeInput animated:NO];
    [passcodeInput release];
}

and the following in all my viewDidLoad, updating the current view controller as I went into each screen (only 2 lines but still seems that there’s a better way):

PasscodeView *passcodeView = [PasscodeView sharedSingleton];
passcodeView.viewController = [[self navigationController] visibleViewController];

I wish there were a way to have gotten the current view controller from applicationWillEnterForeground but I couldn’t find it – any help here still appreciated.

For consistency, I changed a line and added a line to get a nav bar to match the rest of the app and to include a title.

UINavigationController *passcodeNavigationController = [[UINavigationController alloc] initWithRootViewController:passcodeInput];
[currentController presentModalViewController: passcodeNavigationController animated:NO];
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T04:18:38+00:00Added an answer on May 16, 2026 at 4:18 am

    You can centralize this behavior in your app delegate by implementing

    -(void)applicationWillEnterForeground:(UIApplication*)application;
    

    You might implement a singleton that stores the currently appropriate modal view controller, updating it in viewWillAppear in each of your view controllers.

    Edit: I was assuming that you already had a series of view controllers that you wanted to show. I doubt you actually need it. If you have one called, say PasscodeInputController, then your applicationWillEnterForeground would look something like:

    -(void)applicationWillEnterForeground:(UIApplication*)application {
        UIViewController *currentController =  [window rootViewController];
        PasscodeInputController *passcodeInput = [[PasscodeInputController alloc] init];
    
        [currentController presentModalViewController:passcodeInput animated:NO];
        [passcodeInput release];
    }
    

    I hope that addresses your question more directly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

while coding in iOS 4.3 before, I found while add a view controller's view
What I'm doing: In my app, I'm presenting a modal view controller (containing app
When I run my app in landscape mode, the second time my view controller's
Before iOS4.0 clicking the home button on iPhone exits the application, and Apple had
This was working fine before compiling with iOS4.0 and I can't figure out what's
I'm only getting this error in my app since upgrading to ios4. newsDetailController.news =
My goal is to write a custom camera view controller that: Can take photos
It worked just fine before I updated iOS4.3 After that, the delegate methods for
Before I do this I figured I would ask if it was the best
I've built a small app using storyboards and it ran great. Just before final

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.