Xamarin.Essentials 如何处理 iOS “文档”文件夹?

How does Xamarin.Essentials deal with the iOS “Documents” folder?

我按照“build mobile apps with Xamarin.Forms” course. On the “store local data with SQLite in a Xamarin.Forms app”部分,他们说iOS提供了两个文件夹来处理保存在设备上的文件:

那么,本小节介绍:

我不明白的是:这是处理 iOS Documents 文件夹的正确方法吗?我问这个是因为他们明确地说 libFolder 包含适当的 Library 位置。 Apple 指南要求的 Documents 文件夹怎么样?

在iOS中有关于文件夹不同用途的详细信息,在this document中:

文件:/

Use this directory to store user documents and application data files.

The contents of this directory can be made available to the user through iTunes file sharing (although this is disabled by default). Add a UIFileSharingEnabled Boolean key to the Info.plist file to allow users to access these files.

Even if an application doesn’t immediately enable file sharing, you should avoid placing files that should be hidden from your users in this directory (such as database files, unless you intend to share them). As long as sensitive files remain hidden, these files will not be exposed (and potentially moved, modified, or deleted by iTunes) if file sharing is enabled in a future version.

You can use the Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments) method to get the path to the Documents directory for your application.

The contents of this directory are backed up by iTunes.

图书馆/:

The Library directory is a good place to store files that are not created directly by the user, such as databases or other application-generated files. The contents of this directory are never exposed to the user via iTunes.

You can create your own subdirectories in Library; however, there are already some system-created directories here that you should be aware of, including Preferences and Caches.

The contents of this directory (except for the Caches subdirectory) are backed up by iTunes. Custom directories that you create in Library will be backed up.

请阅读文档,如有其他问题欢迎随时咨询

更新

访问更新答案:

iOS:

string docFolder = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
string libFolder = System.IO.Path.Combine(docFolder, "..", "Library");

Android:

string path = Environment.GetFolderPath(Environment.SpecialFolder.Personal);