Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Checking for new data in JSON feed

MightyGMightyG LebanonPosts: 6New Users Noob
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

  • C6Silver05C6Silver05 SeattlePosts: 632New Users @ @ @
    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.
  • MightyGMightyG LebanonPosts: 6New Users Noob
    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 ...
  • MightyGMightyG LebanonPosts: 6New Users Noob
    In other words, I want to create something like the following tutorial http://www.ibm.com/developerworks/library/x-ioschat/index.html but instead of the timer a way to make the tableview reload as soon as new data is added to the database.
  • ryantcbryantcb Posts: 664Registered Users @ @ @
    Well you have to query query the database. Can you not have a date field that field that you check if it's changed from last time you accessed it. If it has update table
  • C6Silver05C6Silver05 SeattlePosts: 632New Users @ @ @
    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.
  • StickStick ColoradoPosts: 79Moderators, Administrators, iPhone Dev SDK Supporter, Registered Users Admin
    edited April 2015
    MightyG wrote: »
    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.
  • C6Silver05C6Silver05 SeattlePosts: 632New Users @ @ @
    Stick wrote: »
    MightyG wrote: »
    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.

  • StickStick ColoradoPosts: 79Moderators, Administrators, iPhone Dev SDK Supporter, Registered Users Admin
    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.
  • C6Silver05C6Silver05 SeattlePosts: 632New Users @ @ @
    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.
  • MightyGMightyG LebanonPosts: 6New Users Noob
    I liked the idea of the time stamp. I have also found this tutorial: http://www.raywenderlich.com/3932/networking-tutorial-for-ios-how-to-create-a-socket-based-iphone-app-and-server that teaches how to use web sockets to achieve my goal. Thank for your replies
Sign In or Register to comment.