What is the best Environment.SpecialFolder for store application data in Xamarin.Forms?

人走茶凉 提交于 2019-11-29 07:33:27

问题


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

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:

  • user and password data
  • other application specyfic data

??

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


回答1:


Storing small Key-Value Pairs:

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.

Storing Documents/Database (Sqlite):

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

Android:

Environment.SpecialFolder.Personal & MyDocuments both maps to: /data/data/@PACKAGE_NAME@/files

Environment.SpecialFolder.LocalApplicationData maps to: /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 all map to: /Documents

iOS has following directory structure:

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

/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: Not visible in iTunes. Can be backed up by iTunes/iCloud except Caches directory.

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

To get to the Library Path:

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

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

Find basics about iOS File System Basics.



来源:https://stackoverflow.com/questions/47237414/what-is-the-best-environment-specialfolder-for-store-application-data-in-xamarin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!