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 8343275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:00:36+00:00 2026-06-09T06:00:36+00:00

what method within a ViewController’s class can I call to check when it has

  • 0

what method within a ViewController’s class can I call to check when it has been brought to the foreground?

For example Im looking at a page on my application and I decide to close the application and go back to it later. When I go back to it the same view as I was looking at was on the screen. However… As soon as I open the application I want to segue over to another view.

How can I do this?

Currently trying this:

 - (void) applicationDidBecomeActive:(NSNotification*) notification
{
    [self checkActivity];
    // Do your stuff here
}


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(applicationWillEnterForeground:)
                                                     name:UIApplicationWillEnterForegroundNotification
                                                   object:nil];
        [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(applicationDidBecomeActive:)
                                                     name:UIApplicationDidBecomeActiveNotification
                                                   object:nil];
    }
    return self;
}

- (void)checkActivity{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSLog(@"Checking if re-authentication required...");
    if([[defaults objectForKey:@"shouldgotologin"] isEqualToString:@"yes"]){
        NSLog(@"View Should go to login...performing segue");
        [defaults setObject:@"no" forKey:@"shouldgotologin"];
        [defaults synchronize];
        [self performSegueWithIdentifier:@"backtologin" sender:self];
    } else {
        NSLog(@"Should go to login is not true.");
    }
}
  • 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-06-09T06:00:39+00:00Added an answer on June 9, 2026 at 6:00 am

    Register your view controller to observe UIApplicationWillEnterForegroundNotification:

    1) Inside view controller’s init method:

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(applicationWillEnterForeground:)
                                                 name:UIApplicationWillEnterForegroundNotification
                                               object:nil];
    

    2) Inside view controller’s dealloc method:

    [[NSNotificationCenter defaultCenter] removeObserver:self];
    

    3) Also, have your view controller implement this method:

    - (void) applicationWillEnterForeground:(NSNotification*) notification
    {
        // This method will be called just before entering the foreground;
        // Do your stuff here
    }
    

    If the timing of UIApplicationWillEnterForegroundNotification doesn’t suit you, check all the available notifications for UIApplication here:
    http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIApplication_Class/Reference/Reference.html

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

Sidebar

Related Questions

My AppDelegate_Phone class has the method -(void)doSomething . How can I call that from
Can I call public method from within private one: var myObject = function() {
This one has me stumped. I need to call an activity method from within
I am calling the following Class method from within my ViewController init method: [NSURLConnection
I have a class with this method call within dealloc: - (void)dealloc { [[NSNotificationCenter
I wanted to call Test1() Method Within WaitAndCallFunc() Function. Code: typedef void (*func)(); void
I am attempting to call the Apache Commons StringUtils.join() method from within a Groovy
Shouldn't I be able to call this CoffeeScript method from within an erb template?
I have a ViewController class that has a property that is the model which
I need to call a method in the viewcontroller that creates a popupviewcontroller, from

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.