I have a simple Xamarin Forms app. I've now got a simple POCO object (eg. User
instance or an list of the most recent tweets or orders or whatever).
How can I store this object locally to the device? Lets imagine I serialize it as JSON.
Also, how secure is this data? Is it part of Keychains, etc? Auto backed up?
cheers!
By far the biggest drawback of Xamarin can be its price. Xamarin itself is Free and Open-Source, but that changes when you want to use it in an enterprise setting. Although you can use any IDE to develop with Xamarin, in order to take full advantage of Xamarin's features, you'll probably want to use Visual Studio.
In May 2020, Microsoft announced that Xamarin. Forms, a major component of its mobile app development framework, would be deprecated in November 2021 in favour of a new . Net based product called MAUI - Multiform App User Interface.
You have a couple options.
I think you'll have to investigate and find out which route serves your needs best.
As far as security, that depends on where you put your data on each device. Android stores app data in a secure app folder by default (not all that secure if you're rooted). iOS has several different folders for data storage based on different needs. Read more here: iOS Data Storage
Another option is the Xamarin Forms settings plugin.
E.g. If you need to store a user instance, just serialize it to json when storing and deserialize it when reading.
Uses the native settings management
Windows RT / UWP: ApplicationDataContainer
public User CurrentUser { get { User user = null; var serializedUser = CrossSettings.Current.GetValueOrDefault<string>(UserKey); if (serializedUser != null) { user = JsonConvert.DeserializeObject<User>(serializedUser); } return user; } set { CrossSettings.Current.AddOrUpdateValue(UserKey, JsonConvert.SerializeObject(value)); } }
EDIT: There is a new solution for this. Just use Xamarin.Essentials.
Preferences.Set(UserKey, JsonConvert.SerializeObject(value)); var user= JsonConvert.DeserializeObject<User>(Preferences.Get(UserKey, "default_value");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With