如何在Xamarin Forms应用程序本地保存一些用户数据? [英] How can I save some user data locally on my Xamarin Forms app?

查看:454
本文介绍了如何在Xamarin Forms应用程序本地保存一些用户数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的Xamarin Forms应用程序.现在,我有了一个简单的POCO对象(例如User实例或最新推文或订单的列表等).

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).

如何将该对象本地存储到设备?假设我将其序列化为JSON.

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?

欢呼!

推荐答案

您有两种选择.

  1. SQLite.此选项是跨平台的,如果您有大量数据,则效果很好.您还将获得额外的交易支持和异步支持. 编辑:过去,我建议使用 SQLite.Net-PCL .由于问题涉及到Android 7.0支持(并且显然不再支持)我现在建议使用最初来自以下项目的项目: sqlite-net
  2. 本地存储.有一个很棒的支持跨平台存储的小工具.有关更多信息,请参见 PCLStorage
  3. 还有 Application.Current.Properties 在Xamarin.Forms中实现,允许简单的键值对数据.
  1. SQLite. This option is cross-platform and works well if you have a lot of data. You get the added bonus of transaction support and async support as well. EDIT: In the past I suggested using SQLite.Net-PCL. Due to issues involving Android 7.0 support (and an apparent sunsetting of support) I now recommend making use of the project that was originally forked from: sqlite-net
  2. Local storage. There's a great nuget that supports cross-platform storage. For more information see PCLStorage
  3. There's also Application.Current.Properties implemented in Xamarin.Forms that allow simple Key-Value pairs of data.

我认为您必须进行调查,找出哪种路线最能满足您的需求.

I think you'll have to investigate and find out which route serves your needs best.

就安全性而言,这取决于将数据放置在每台设备上的位置. Android默认将应用程序数据存储在安全的应用程序文件夹中(如果您是root用户,则不是所有安全的文件夹). iOS具有多个不同的文件夹,用于根据不同的需求进行数据存储.在此处了解更多信息: iOS数据存储

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

这篇关于如何在Xamarin Forms应用程序本地保存一些用户数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆