Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 825
zchpit Avatar asked Nov 11 '17 11:11

zchpit


People also ask

What are the various methods of xamarin applications that can be made?

Xamarin is a Microsoft Cross-Platform Mobile Development solution that allows us to create native apps for all platforms (IOS, Android, and UWP) using the C# language. For app development, Xamarin uses two methods: Xamarin. Forms and Xamarin Native.

What is xamarin essentials?

Xamarin. Essentials provides a single cross-platform API that works with any iOS, Android, or UWP application that can be accessed from shared code no matter how the user interface is created. See the platform & feature support guide for more information on supported operating systems.

Are xamarin Apps good?

Since its appearance in 2011, Xamarin has become a great option for cross-platform app development, a faster way to build iOS, Android, and Windows apps.


1 Answers

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.

like image 144
MilanG Avatar answered Sep 28 '22 22:09

MilanG