我应该使用哪个文件系统目录来存储文件? [重复]

时间:2022-09-10 22:49:53

This question already has an answer here:

这个问题在这里已有答案:

I just read through this link about ios file system. However, I still unable to decide how to properly store files in my app.

我刚读完了这个关于ios文件系统的链接。但是,我仍然无法决定如何在我的应用程序中正确存储文件。

My app basically does the following.

我的应用基本上做了以下。

  • display all sorts of files from the net. (docx, pdf, video, images, etc)

    显示网络中的各种文件。 (docx,pdf,视频,图像等)

  • user can choose to save offline for the above files.

    用户可以选择离线保存上述文件。

From the link, I think I have 3 directory choices.

从链接,我认为我有3个目录选择。

  • Documents/ (recommended for user-generated or cannot be downloaded)

    文件/(建议用户生成或无法下载)

  • tmp/ (after done with files, should be deleted)

    tmp /(完成文件后,应删除)

  • Library/caches (system will delete, but caches store longer than tmp)

    库/缓存(系统将删除,但缓存存储时间超过tmp)

So, my questions are,

所以,我的问题是,

  • where should I put if the user choose to save offline?
  • 如果用户选择离线保存,我应该放在哪里?

  • where should I put if the user decided not to save offline? I am using UIDocumentInteractionController
  • 如果用户决定不离线保存,我应该放在哪里?我正在使用UIDocumentInteractionController

Also, I am a bit confused between cashes and tmp.

而且,我在兑现和tmp之间有点困惑。

It would be nice if you can provide me sample code or link to tutorial blogs. Thanks!

如果您可以提供示例代码或链接到教程博客,那将是很好的。谢谢!

2 个解决方案

#1


0  

For offline, you should store them in the Documents folder so that the system won't delete them automatically.

对于脱机,您应将它们存储在Documents文件夹中,以便系统不会自动删除它们。

If there is no other use of the file, you should not download them at all.

如果没有其他文件使用,则根本不应下载它们。

#2


0  

You should store downloaded files in /Documents if you want to display them in future. You should provide an option to delete them.

如果要在将来显示它们,则应将下载的文件存储在/ Documents中。您应该提供删除它们的选项。

There is two well-written library to reduce your effort.

有两个写得很好的库可以减少您的工作量。

https://github.com/JohnSundell/Files by John Sundell

https://github.com/JohnSundell/由John Sundell撰写

https://github.com/sketchytech/SwiftFiles by Anthony Levings

https://github.com/sketchytech/SwiftFiles由Anthony Levings提供

#1


0  

For offline, you should store them in the Documents folder so that the system won't delete them automatically.

对于脱机,您应将它们存储在Documents文件夹中,以便系统不会自动删除它们。

If there is no other use of the file, you should not download them at all.

如果没有其他文件使用,则根本不应下载它们。

#2


0  

You should store downloaded files in /Documents if you want to display them in future. You should provide an option to delete them.

如果要在将来显示它们,则应将下载的文件存储在/ Documents中。您应该提供删除它们的选项。

There is two well-written library to reduce your effort.

有两个写得很好的库可以减少您的工作量。

https://github.com/JohnSundell/Files by John Sundell

https://github.com/JohnSundell/由John Sundell撰写

https://github.com/sketchytech/SwiftFiles by Anthony Levings

https://github.com/sketchytech/SwiftFiles由Anthony Levings提供