ios - 在 IOS 中存储应用程序数据的正确位置

标签 ios iphone ipad nsdocumentdirectory nscache

目前我正在将我的应用程序数据(媒体)保存到 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 中。有些文件永远不能公开,有些文件必须共享。存储文件的理想方式应该是什么。

最佳答案

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

使用 Application Support (NSApplicationSupportDirectory) 来处理您希望对用户隐藏但仍然被备份并且永远不会被操作系统删除的文件。

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

相关文章:

ios - 屏幕分辨率 iOS 设备和图形

ios - AB地址簿内存泄漏

ios - 在ios中添加一个控件到新的联系人屏幕

ios - swift : Redundant conformance of Viewcontroller to protocol UIGestureRecognizerDelegate

iphone - UITabBar 选择指示器图像填充

javascript - 提交表单时如何防止iPad键盘死机?

iphone - popViewController 不会自动旋转回允许的方向

iphone - View Controller 的全局实例是否应该由应用程序委托(delegate)拥有

ios - 选择器方法不调用

iphone - 使用 Storyboard View Controller 创建编程选项卡栏?