Search code examples
ioslong-polling

how to implement polling iphone sdk?


I want to know how we can auto refresh a uitableview by using polling. I have a table which contains messages users sent. So when I load the view i use AFTNetworking to get the JSOn response and display it in the uitableview. Now if the user stays on the screen and we get a new message posted it should automatically refresh the uitableview.So far what I can do it to call the url at certain time intervals. Any solutions to that?


Solution

  • Following Timer will invoke "loadNewData" after each 10 seconds

    NSTimer *refreshTimer = [NSTimer scheduledTimerWithTimeInterval:10.0f target:self selector:@selector(loadNewData) userInfo:nil repeats:YES];
    

    write your loading code in this method

    -(void)loadNewData
    {
        // write code to fetch Data from Server
    }