Dan
Dan

Reputation: 5637

Store Core Data For X Number of Minutes

I'm building an iPhone app which uses your current location to get a series of results from a WCF Service. I then store the data returned by the WCF using Core Data and then populate a TableView.

What I'd like to do is store the results for around 30 minutes then each time the view loads, check whether I need to refresh the data. I would also be watching the users' location so that if they move a considerable distance, the data will also update.

My problem is that I'm not sure what the best approach would be to monitor the age of the data.

Should I store an insert date with the Core Data Entity. Alternatively I could create a new entity to store a global 'last retrieved' date. Or I could just store a value in the plist.

I'm not sure which of my above suggestions would be the best, or even there are any better ones. Any help with this is much appreciated!

Upvotes: 0

Views: 84

Answers (1)

justin
justin

Reputation: 5831

An insertDate attribute would probably be the best bet. Whenever your app becomes loads, you can check the change in time versus that attribute's value. If the time is over 30 minutes, you can fire your reload method, else you can take the remaining time and set up a scheduled NSTimer event that will fire the method when the time runs up. Just be sure to reset the insertDate value once you reload your data

Upvotes: 1

Related Questions