OGeek|极客世界-中国程序员成长平台

标题: ios - 在IOS中存储应用程序数据的正确位置 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 19:28
标题: ios - 在IOS中存储应用程序数据的正确位置

目前我正在将我的应用程序数据(媒体)保存到 CacheDirectory 即

/var/mobile/Applications/BEAFC76C-C450-4A3A-9765-A0385A9580F3/Library/Caches

一切都很顺利。但最近我收到一个错误报告,应用程序数据已被删除。当我搜索它时,我得到了这个 Apple Doc .据此,DocumentsDirectory 应该是存储用户/应用程序数据的理想场所。

Put user data in the /Documents/. User data is any data that cannot be recreated by your app, such as user documents and other user-generated content.

并且不应该使用缓存来存储应用程序无法复制的用户数据。

Put data cache files in the /Library/Caches directory. Examples of files you should put in this directory include (but are not limited to) database cache files and downloadable content, such as that used by magazine, newspaper, and map apps. Your app should be able to gracefully handle situations where cached data is deleted by the system to free up disk space.

存放它的理想位置应该是什么。

编辑:

我有一个应用程序允许用户在应用程序中存储视频和照片。为此,我使用了 CacheDirectory。但是我收到了数据(视频/照片)被删除的错误报告。我得出的结论是设备本身正在删除数据以提供空间。

其次,我也想给 iTunes 分享功能。所以只有特定的文件必须存储在 DocumentsDirectory 中。有些文件永远不能公开,有些文件必须共享。存储文件的理想方式应该是什么。



Best Answer-推荐答案


对您希望通过 iTunes 共享的文件使用 Documents (NSDocumentDirectory)。

Application Support (NSApplicationSupportDirectory) 用于您希望对用户隐藏但仍被备份且不会被操作系统删除的文件。

关于ios - 在IOS中存储应用程序数据的正确位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47835808/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4