在Xamarin.Forms中存储应用程序数据的最佳Environment.SpecialFolder是什么? [英] What is the best Environment.SpecialFolder for store application data in Xamarin.Forms?

查看:141
本文介绍了在Xamarin.Forms中存储应用程序数据的最佳Environment.SpecialFolder是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Xamarin.Forms和移动开发的新手.我想将我的应用程序用户的用户名和加密密码存储在移动设备上的文件中.我正在使用xamarin表格技术.我知道有很多differnete文件夹.例如:

I'm new in Xamarin.Forms and mobile development. I want to store user and encrypted password of my application user in file on mobile device. I'm using xamarin forms technology. I kwnow that there are many differenet folders. In example:

System.Environment.SpecialFolder.Personal
System.Environment.SpecialFolder.LocalApplicationData
System.Environment.SpecialFolder.MyDocuments

您可以在这里找到完整列表: https://msdn.microsoft.com/en-gb/en-enl/library/system.environment.specialfolder(v = vs.110).aspx

Full list you can find here: https://msdn.microsoft.com/en-gb/en-enl/library/system.environment.specialfolder(v=vs.110).aspx

最适合存储的文件夹/目录是什么

What is the best folder / catalog for store:

  • 用户和密码数据
  • 其他应用专用数据

??

我发现个人"对我很有用,但是如果您有其他答案,也请发布. SpecialFolder.个人位置

I have found that "Personal" is good for me, but if you have other answers post it as well. SpecialFolder.Personal location

推荐答案

存储小型键值对:

Storing small Key-Value Pairs:

Xamarin.Forms实现 Application.Current.Properties 将键值数据存储在应用程序的本地存储中,只有存储它们的应用程序才能安全地访问这些键值对.

Xamarin.Forms implements Application.Current.Properties which stores the key value data in the local storage of the app and access to these key-value pairs are secure to that app only who stored them.

存储文档/数据库(Sqlite):

Storing Documents/Database (Sqlite):

每个平台都有其自己的文件夹结构,用于在下面存储应用程序特定的数据/文件.

Each platform has it's own folder structure to store app specific data/files underneath.

Android :

Environment.SpecialFolder.Personal & MyDocuments都映射到:/data/data/@PACKAGE_NAME@/files

Environment.SpecialFolder.LocalApplicationData映射到:/data/data/@PACKAGE_NAME@/files/.local/share

我们可以根据文件在文件系统中的映射方式将文件存储在上述任何目录中. 除非手机已扎根,否则其他应用都无法访问以上目录,用户也无法在世界以外的地方访问它们.

We can store files in any of the above directories based on how they are mapped in the file system. None of the above directories can be accessed by other app, nor user can access them outside the world unless the phone is rooted.

iOS :

Environment.SpecialFolder.Personal, LocalApplicationData & MyDocuments全部映射到:/Documents

iOS具有以下目录结构:

iOS has following directory structure:

/Documents
/Library
/Library/Application Support
/Library/Caches
/tmp

/Documents::如果在应用程序的info.plist中打开了iTunes共享,则在iTunes中显示.内容可以通过iTunes/iCloud备份.

/Documents: Gets visible in iTunes If iTunes sharing is turned on in info.plist in the app. Content can be backed up by iTunes/iCloud.

/Library:iTunes中不可见.可以由iTunes/iCloud备份,除了Caches目录.

/Library: Not visible in iTunes. Can be backed up by iTunes/iCloud except Caches directory.

不需要公开给用户的文件/数据应存储在Library目录中.前任.数据库文件.我会去Library目录以增加安全性以及加密(如果需要).

Files/Data which doesn't need to expose to user should be stored in Library directory. Ex. database files. I would go for Library directory for add on security along with encryption (if required).

要转到库路径:

Path.Combine(Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments), "..", "Library");

要了解有关每个Enumeration映射的详细信息,其目录为转到此处.

To know more on each Enumeration's mapping with directory Go Here.

找到有关iOS的基础文件系统基础.

Find basics about iOS File System Basics.

这篇关于在Xamarin.Forms中存储应用程序数据的最佳Environment.SpecialFolder是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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