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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:38:44+00:00 2026-06-04T14:38:44+00:00

I need to schedule a task in background when the application enter background state.

  • 0

I need to schedule a task in background when the application enter background state.
I have to do this in order to call a remote service each x time and then show a local notification when some event happend with the remote service.
(I know it’s looks like RPN, yes it is, but for some reason I am not able to use PRM)

I tried this code :

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

   [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^(void){
        remoteServiceCallThread = [[NSThread alloc] initWithTarget:self selector:@selector(doRemoteCall:) object:nil];
        [remoteServiceCallThread start];
   }];
}

- (void)applicationWillEnterForeground:(UIApplication *)application{
    [remoteServiceCallThread cancel];   
}

I put breakpoint in the doRemoteCall selector, put is not working.

Maybe my approach is not the best one. If you have any other hack to doing this operation like I describe it I’ll take it.

Thank you.

  • 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-04T14:38:46+00:00Added an answer on June 4, 2026 at 2:38 pm

    You are not starting the thread, it’s initialization code is at the expiration handler block which will be called right before the app is shut down with a timeout:

    A handler to be called shortly before the application’s remaining
    background time reaches 0. You should use this handler to clean up and
    mark the end of the background task. Failure to end the task
    explicitly will result in the termination of the application. The
    handler is called synchronously on the main thread, thus blocking the
    application’s suspension momentarily while the application is
    notified.

    The task should be active for 10 minutes only (that is driven by iOS) if your app is not supporting one of the background modes (gps, audio, voip).

    You also need to keep the returned UIBackgroundTaskIdentifier reference to be able to mark it as ended if the user brings the app to foreground or when task time is going to the end (that’s when the handler block is called).

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

Sidebar

Related Questions

I need to schedule a console application to run daily at a certain time
I need an application/service which runs in the background and generate bills on a
I have an application that I need to automate where at a certain time
i am using Windows and i need to schedule a php task in this.
Users of my application need to be able to schedule certain task to run
In my application I need to have periodically run background tasks (which I can
I need to schedule a task to run in at fixed interval of time.
I need to schedule a task to run on the last night of each
I need to make something(i call it a scheduler) that checks the time of
I need to run a macro in an Excel spreadsheet through a schedule task.

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.