How to store persistent data between sessions?

I’d like to store some data between sessions of my application running. (Specifically: the user’s log-in details!)

What’s the best practice for this?

I’ve found Uno.IO.File, which I suppose would do the trick, but what path/filename should I use so that it will work on all platforms?

I’m using:

File.WriteAllText(Directory.GetUserDirectory(UserDirectory.Data + "/Filename.txt")
File.ReadAllText(Directory.GetUserDirectory(UserDirectory.Data + "/Filename.txt")

to store data. Works on every platform except webgl as far as I know

Thanks! do you think it’s safe? Should I store access tokens etc like this?

Håvard’s approach is OK for most use cases.

If you have particular security concerns, look up the prefered way of doing it using the iOS and Android APIs respectively.

Note that you can add references to the Android and Experimental.iOS packages to access any of the native APIs directly from Uno code.

Yeah forgot to say. The data I store is very non sensitive, so security wasnt a concern :slight_smile:

hello, i need to do the same, store the user id, name, username, profile pic path, and session token (from parse) for that user and some device data like the id of the instalation and stuff like that, is it safe to do it this way?

(that file is per instalation, so it’s data is unique to each phone)

also, i need to check if that file exist when you open the app and if it does, get the data of the file and store it on variables in the app.


yup, exactly the same use-case :slight_smile: