iosparse-platformsavelocal-datastore

Parse iOS - How to save an PFObject locally and manually upload to server later?


I want to create a PFObject and have it saved locally so that if the user quits the app (or heaven forbid, it crashes) the object is still intact on the device BUT not uploaded to the server until the user is ready to submit it. Is this possible?

I know there is the 'saveEventually' method, but my understanding of that is it will at some point save itself to the server automatically, which is not what I want. I want to save locally only and only upload to the server when the user is completed finished.


Solution

  • If you have enabled the local datastore, calling pinObjectInBackground() on an object should make the object persist between sessions. Every time you make changes to the object that you want to save, call pinObjectInBackground() again. The object will not be saved to the server until you call saveEventually() or some other save function. Any query using fromLocalDatastore() will be able to fetch your locally stored object as long as it is pinned.