What’s the best way to maintain user data persistently until an Internet connection is available, whereupon it can be sent to a server? I am envisioning something like the way Unity Analytics does it. Is there something built-in to Unity or a 3rd party plugin that will help with this?
“sent to a server” isn’t very descriptive of what kind of server, what kind of data, etc. Without any more information you can consider any number of persistent storage methods, from PlayerPrefs, to json or even csv, etc.
My question is high-level because I don’t have specific information at this time. But here’s an example: Let’s say that I want to present a login form. The user might login while the app is offline (how offline authentication works is TBD). I want to record each successful login in a remote database, so the next time the app detects that it is online, it sends its cached data to a web service. Unity Analytics apparently works this way, so is there something there that I can use?
I’m sure you could serialize a class containing lists of everything that you want to store, write it to disk, and when you can confirm connection, send them first-in-first-out.
I don’t know anything about tapping into methods used for caching data by Unity Analytics, or if that were even possible. If I were just trying to cache a few values like login attempts, I’d probably just write them to PlayerPrefs, and when you get a successful connection you upload that data to your server, then clear out the sent values in PlayerPrefs.
I believe PlayerPrefs is implemented on every platform, and you don’t need to worry about any platform dependent filesystem issues, permissions, etc. You can use simple variables, or serialize classes, though people have reported issues when you try to use PlayerPrefs for fairly large amounts of data. If you were doing that then I’d write it out as a file to disk.
imo, it would be best to keep a JSON data file in the Application.persistentDataPath to hold onto until the client is back online… then transmit. Makes it really easy to store pretty much anything you want.
if any security is needed you could easily wrap a compressed file with some AES on it.