dan martin
dan martin

Reputation: 1317

Parse - How to update tableView as more data is added to the parse database?

My question is to do with the backend service parse. So far, whenever I need something, I use a PFQuery to query the database. However, I now need something a little different, and have run into a slight wall.

I have a game app that records the all time high scores. Now, I want the app to auto-update the table of high scores as more come in. For example, if the first row is currently "Jimmy: 2505" and in parse suddenly another bit of data is added where Sam gets 2604, I want Sam to be at the top of the table now.

I realise that I could just continuously send a query to Parse say every 30 seconds to check for new data, but that would be terribly inefficient, and also expensive. Is there any way that I can use that allows auto-updating without sending a query all the time? Thanks

Upvotes: 1

Views: 275

Answers (1)

Michael E
Michael E

Reputation: 674

I'd suggest using push notifications. When the user opens the app, or uses a particular view controller, subscribe them to a channel that calls for updates when the high score list is updated. In your app delegate configure how you want the push notifications to be handled. You'll have to weigh the pros and cons of api requests generated using push notifications vs a default call to update the high score list every 30 seconds as you suggested in the OP.

Push notifications should be triggered through cloud code. When a new high score is generated make a cloud call that triggers the push notifications. You can specify the kind of push notification that you'll be sending.

Upvotes: 1

Related Questions