将应用程序文档中的特定目录与文件共享

时间:2018-12-13 22:18:00

标签: ios objective-c file

我使用文件管理器创建了一个iOS应用,该应用可在“文档”的子文件夹内浏览。 应用程序文档中的文件夹为:

  • 设置
  • Tmp
  • 垃圾桶

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

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

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

它起作用了,但是所有文件夹都暴露了,我只想暴露“ Root”文件夹。

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

非常感谢您。

1 个答案:

答案 0 :(得分:2)

在使用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.

enter image description here

如果您希望某些内容不向用户公开,请不要使用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.

enter image description here

在这里,请看上面链接中的以下屏幕截图,其中显示了何时使用哪个目录?

enter image description here

简而言之,将根目录的内容保留在Document目录中,并将所有其他目录及其内容移动到Library目录或Library / Application Support Directory。这样,您的预期目标就会实现。

相关问题