Quick Links

Checking for new data in JSON feed

Hello I have an app which displays data in a tableview extracted from a JSON feed which gets the data from a mysql database. How to check when a new item has been added to the database therefore to the JSON and reload the tableview accordingly.

Replies

I take it you are using a web service called from your app to get this data, correct? If so, you either have to poll the server for changes or have the server notify your app through something like notifications.

The problem is that I can't poll the server cause the info will be updated on an arbitrary time interval and not a constant one. I want the app to refresh directly when the info is added to the server. And I can't use push notification because it's not something really reliable. The user might stop those notifications, the notification could not be delivered for some kind of reason ...

You are correct about the limitation of push. I would opt to use push and if the user doesn't allow it have it fall over to a timed approach. I get that polling is very wasteful so you have to send it the smallest possible package in an interval your are comfortable with (5 seconds, 10 seconds, etc.) As @ryantcb said, perhaps you use date/time and have your app send that to the server each time. If the server has been updated the update date/time will be different and the server will then send the refreshed data. If it isn't, the server can send a very small JSON wrapped boolean reply so that your app knows not to do anything.

I want the app to refresh directly when the info is added to the server.

You can probably tell your database programmer to somehow post a notification when new material is available. If you have no idea who he is, I like what C6 and Ryan said above my comment. You can always ping the server on a selected time interval that you know the data will become available every X seconds but be extremely careful with the memory overhead, that is a super "hacky" way of doing it though and I would only use it as a last resort. Contact your Database programmer.

I want the app to refresh directly when the info is added to the server.

You can probably tell your database programmer to somehow post a notification when new material is available.

@Stick What are you thinking in terms of "posting a notification" from the server side? Are you talking about opening a persistent socket between the server and the app? Without using APNS I am not sure how you would use notifications without a 1:1 socket connection. Curious is there is another approach.

Good point, I'm not a DB programmer so I cannot speak to the finer details. I do know however you can ping the server to see if there is new information available, and your DB programmer can definitely either let you know personally when it will be, or ask him his opinion on how to check with his server.

I think from the DB side the best they could probably do is have a trigger that writes a timestamp to an activities table of which your app can poll (or the server when a request comes in). You could actually use this for both the polling and notification approaches. For the latter instead of the app polling, the server would send an APNS package that would alert the app to go get the data directly.