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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:23:14+00:00 2026-06-10T02:23:14+00:00

I´m working on an application in which, when it is pushed in background via

  • 0

I´m working on an application in which, when it is pushed in background via the home button, a timer should start and when the application gets back to foreground and the timer has passed a certain amount of time, something should be executed.

My questions are

  1. How do I handle the events when my app goes to
    background/foreground?
  2. Is there a special method or an other technique?

Thanks a lot.

  • 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-10T02:23:15+00:00Added an answer on June 10, 2026 at 2:23 am

    A possible implementation could look like:

    #define YOUR_TIME_INTERVAL 60*60*5   //i.e. 5 hours
    
    - (void)applicationDidEnterBackground:(UIApplication *)application
    {
        //... your oder code goes here
    
        NSNumber *timeAppClosed = [NSNumber numberWithDouble:[[NSDate date] timeIntervalSince1970]];
        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
        [defaults timeAppClosed forKey:@"time.app.closed"];
        [defaults synchronize];
    }
    

    and

    - (void)applicationWillEnterForeground:(UIApplication *)application
    {
        NSNumber *timeAppClosed = [[NSUserDefaults standardUserDefaults] valueForKey:@"time.app.closed"];
        if(timeAppClosed == nil)
        {
            //No time was saved before so it is the first time the user
            //opens the app
        }
        else if([[NSDate date] timeIntervalSinceDate:[NSDate dateWithTimeIntervalSince1970:[timeAppClosed doubleValue]]] > YOUR_TIME_INTERVAL)
        {
            //Place your code here
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on application which has workflow like this: 1.parsing home page (using HttpURLConnection,
I'm working on an application which has data imported from a foreign (and wholly
I have a working application which gets the GPS Long/Lat of from a BlackBerry
Am working on an application which has a requirement to download bulk data from
I'm working on an application which has different types of users i.e. students, tutors,
I'm working on a application which has Java web interface hosted on Glassfish server
I'm working on web application which has a database UserName|Password|UserType Anil|Anil|Manager ghouse|Ghouse|Admin raghu|raghu|User Now
I have a working web application which already has a login and registration system.
In an application I'm working on I've created a lightweight logger which has two
I'm working on a application which supports several languages and has a functionality in

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.