Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
762 views
in Technique[技术] by (71.8m points)

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...