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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:33:27+00:00 2026-06-13T13:33:27+00:00

I need to poll data from server periodically in my iOS application. I need

  • 0

I need to poll data from server periodically in my iOS application. I need to do it every 10 seconds in a thread, in order to keep the UI usable. This function will be fired when the user logs in. I’m thinking about using NSRunLoop with NSTimer to achieve this functionality, and maybe use AFNetworking to get JSON data.

Is this the correct approach? Should this be done using GCD?

  • 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-13T13:33:28+00:00Added an answer on June 13, 2026 at 1:33 pm

    Probably the only part that must be done off the main thread is the request itself. Deciding that you need a request and forming that request can be done without any fancy stuff…

    Agree with H2CO3 that polling might become a problem for your server with too many clients in the wild, but also agree with you that it’s not necessarily a mistake in all cases.

    Setup a timer …

    [NSTimer scheduledTimerWithTimeInterval:10.0
                                     target:self
                                   selector:@selector(timerFired:)
                                   userInfo:nil
                                    repeats:YES];
    

    Run a request …

    - (void)timerFired:(NSTimer *)timer {
    
        NSURLRequest *request = // setup your request
        [NSURLConnection sendAsynchronousRequest:request 
                                           queue:[NSOperationQueue mainQueue]
                               completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
        if (!error) {
           // change my model in an observable way, or
           // if we're in a vc, change my model and update the UI
    
           // if we want to stop polling, [timer invalidate];
        }
    }];
    

    NSTimer fires periodically. Upon fire, a method (on the main thread) decides if it needs to poll (in the case you described, always ‘yes’ if it’s called on a 10sec period). Form the request, NSURLConnection sendAsynchronousRequest: will move the slow part of the request off the main. The block on sendAsynch runs back on the main when the request is done.

    The trick is that other parts of your app need to be setup to observe changes in the model and update the views. This may be as simple as doing a table reload in the sendAsynch block, or more complex, like setting up KVO that will trigger as the model changes.

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

Sidebar

Related Questions

I need to submit data from a web application to console application. The current
I have a binary log file with streaming data from a sensor (Int16). Every
In general chat application, client's browser always poll to server to check for new
For example I need to retrieve a value from this session. How should I
Are there any ways in ASP.net to fetch data from the server without extending
I’m using a Clojure application to access data from a web API. I’m going
I have written stored procedure to poll the data from the database in biztalk.but
I use $.ajax() to poll an action method every 5 seconds as follows: $.ajax({
I'm attempting to grab data sets from a file named poll.txt and then use
Need to apply a filter to a file like this: TUPAC_0006:1:1:2554:2356#0/1 0 * 0

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.