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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:43:42+00:00 2026-05-28T06:43:42+00:00

My application has to poll a server for a maximum of 10 minutes (using

  • 0

My application has to poll a server for a maximum of 10 minutes (using RestKit), even if the application is sent to the background. (polling always starts while the application is in the foreground)

I have a View Controller (not the RootViewController) that listens to applicationDidEnterBackground.

Also, there’s a class “Order” that has a method “poll” which is used to send a request to the server, and several other callback methods for “timeout”, “request cancel”, “handle response”, etc.

- (void)poll
{
    RKRequest* request = [[RKClient sharedClient] requestWithResourcePath:@"/foo.php" delegate:self];
request.backgroundPolicy = RKRequestBackgroundPolicyContinue;    
[request send];    

NSLog(@"I am your RKClient singleton : %@", [RKClient sharedClient]);        
}
- (void)requestDidStartLoad:(RKRequest *)request {
NSLog(@"requestDidStartLoad");
}
- (void)requestDidTimeout:(RKRequest *)request {
NSLog(@"requestDidTimeout");
}
- (void)request:(RKRequest *)request didFailLoadWithError:(NSError *)error {
NSLog(@"didFailLoadWithError");
}
- (void)request:(RKRequest*)request didLoadResponse:(RKResponse*)response 
{  
}

While the app is in the foreground, everything works fine and the callbacks are triggered.

When my application enters the background i want to continue polling the server. I use this method, “poll” is called, but no callbacks are triggered..

- (void)applicationDidEnterBackground:(NSNotification *) notification 
{
Order *order = [[Order alloc] init];

UIApplication *app = [UIApplication sharedApplication];

__block UIBackgroundTaskIdentifier taskId;

taskId = [app beginBackgroundTaskWithExpirationHandler:^{    
    [app endBackgroundTask:taskId]; 
}];

if (taskId == UIBackgroundTaskInvalid) { 
    return;
}

dispatch_async(dispatch_get_global_queue(0, 0), ^{ 

    while(YES)
    {
        sleep(1);

        [order poll];
    }

    [app endBackgroundTask:taskId]; 
});

[order release];

}

What am I doing wrong?

  • 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-28T06:43:43+00:00Added an answer on May 28, 2026 at 6:43 am

    I don’t know this RKClient you’re using but probably it’s based on NSURLConnection API. This asynchronous API calls delegates only if it’s running inside a run-loop; from NSURLConnection documentation:

    Messages to the delegate will be sent on the thread that calls this method. For the connection to work correctly the calling thread’s run loop must be operating in the default run loop mode.
    

    Unfortunately GCD doesn’t guarantee you to run a block inside a thread which executes a run-loop. The suggestion in such case is that you run your “poll” inside a NSOperation which is optimized for this kind of situations.

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

Sidebar

Related Questions

I need to make application that needs to poll server often, but GAE has
My application has a command line interface, and I'm thinking about using the GNU
Application has an auxiliary thread. This thread is not meant to run all the
My application has a need to let the user choose a date from a
Our application has a file format similar to the OpenDocument file format (see http://en.wikipedia.org/wiki/OpenDocument
My application has no forms. It runs by calling Application.Run();
My application has just started exhibiting strange behaviour. I can boot it through the
My application has a plug-in model that allows third-party developers to write assemblies that
Our application has a service layer and a DAO layer, written as Spring beans.
Our application has many controls that are created dynamically. For example, a navigation pane

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.