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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:18:07+00:00 2026-05-23T11:18:07+00:00

My goal is to run a repeating timer every five seconds if and only

  • 0

My goal is to run a repeating timer every five seconds if and only if the application is running in the background. I’ve tried a couple of ideas, but they don’t seem to work.

Idea 1: Doesn’t run even once.

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

    [NSTimer scheduledTimerWithTimeInterval:(5.0/5.0) target:self selector:@selector(check_expiry) userInfo:nil repeats:YES];

}

Idea 2: Runs every five seconds, but I can’t seem to stop the loop.

- (void)applicationDidEnterBackground:(UIApplication *)application {
    counter = YES;
    while (counter) {
        sleep(5);
        [self check_expiry];
    }
    // Counter is set to NO in willEnterForeground and didBecomeActive, but this loop continues to run due the sleep();
}

How can I get this loop to run properly?

Thanks!

  • 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-23T11:18:08+00:00Added an answer on May 23, 2026 at 11:18 am

    When an application “enters the background” in iOS, that’s not like normal operating systems, where it continues to run. The application enters a suspended state. It doesn’t keep running; only application state is preserved, and even that’s not guaranteed – if the device is running low on memory, iOS will happily terminate your application to give the memory to the active application. If you attempt to block in applicationDidEnterBackground:, like you are doing with sleep(), iOS will simply terminate your application for not returning from that method promptly.

    Your application is woken up periodically if it’s configured for background processing GPS events, VOIP, etc., but abusing those just to get your app to run will stop you from getting App Store approval.

    This is all covered in The iOS Application Programming Guide.

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

Sidebar

Related Questions

We're using the Maven exec:java goal to run a custom java application that configures
I have maven-plagin and need to run goal, that should automatically run before plugin.
My final goal is to write the program which can run on the Unix
Goal Java client for Yahoo's HotJobs Resumé Search REST API . Background I'm used
goal: I have the string 1234432144 I want to only replace the first 2
Maven newbie question :) For 'war' packaging, war:war default goal run in 'package' build
The goal is to run some tests given some data in those Xml files.
Is there a way to run a maven goal using keyboard shortcut in Intellij
I'm having trouble getting Code Analysis to run on the build server. My goal
Basic Goal is that i have four progress bar and want to run them

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.