How to use NSURLSession and NSURLRequest to fetch users feeds and update in a tableview for a social networking iOS app?

StackOverflow https://stackoverflow.com/questions/23453421

  •  15-07-2023
  •  | 
  •  

Question

I am creating a social networking app in iOS for a university group and it's supposed to have display user feeds just like Facebook.

I am saving status updates in MySql database on a server. to update status I am using NSURLRequest and NSURLSession to send status data in post variables to the status update web service which uses php to update the database.

Now, I am confused about displaying the feeds. Here is what i want to do.

  1. I want to fetch 30 feeds first and display them in tableview.
  2. After 30 feeds if the user clicks on more, I want to be able to add another 30 and so on. just like Facebook, when you scroll to the bottom it shows more feeds.

I know how to make the first request and display 30 feeds, but I dont know how to do it the second time. Do I need to make another request? Can someone please explain how Facebook and Twitter do it?

Was it helpful?

Solution

Your request needs to ask for a specific page or offset of the feed, and your server should handle this.

For the first feed, you'd ask for page 0. The server gives you items 1 - 30. At the app end, you keep track of the page you last requested. On the next request, you ask for page 1, and the server gives you items 31-60.

Alternatively, you can send the ID of the last item you have. So for the first request, you send nothing - the server gives you items 1-30. On the second request, you say "the last item in my current list is ID 14152" and the server gives you the next 30 items older than that.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top