首页 > 解决方案 > 与文件应用程序共享应用程序文档中的特定目录

问题描述

我创建了一个带有文件管理器的 iOS 应用程序,可以在 Documents 的子文件夹中浏览。应用程序文档中的文件夹是:

该应用程序的文件管理器仅在“根”文件夹内浏览。其他文件夹必须对用户隐藏且不可访问。

我想与 iOS 自带的 Files App 共享“Root”文件夹,所以我在 info.plist 中添加了以下键:

<key>UIFileSharingEnabled</key>
<true/>
<key>LSSupportsOpeningDocumentsInPlace</key>
<true/>

它有效,但所有文件夹都暴露了,我只想暴露“根”文件夹。

是否可以在“文件”应用中共享特定文件夹?

非常感谢。

标签: iosobjective-cfile

解决方案


在使用 iOS 文件系统之前,请检查 iOS 文件系统不同目录的使用情况。

您可以参考此链接:https ://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html

根据上面的链接,苹果已经明确提到:

对于文档目录:它清楚地表明this directory should only contain files that you may wish to expose to the user.

在此处输入图像描述

如果你想要一些不应该暴露给用户的东西,那么不要使用Documents目录,而是使用Library目录。

对于Library目录:Use the Library subdirectories for any files you don’t want exposed to the user. Your app should not use these directories for user data files.

在此处输入图像描述

在这里,请参阅上面链接中的以下屏幕截图,其中说明何时使用哪个目录?

在此处输入图像描述

简而言之,将根目录的内容保留在 Document 目录中,并将所有其他目录及其内容移至 Library 目录或 Library/Application Support 目录。因此,您的预期目的将得到实现。


推荐阅读