菜鸟教程小白 发表于 2022-12-11 19:28:03

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


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

<blockquote>
<p><strong>/var/mobile/Applications/BEAFC76C-C450-4A3A-9765-A0385A9580F3/Library/Caches</strong></p>
</blockquote>

<p>一切都很顺利。但最近我收到一个错误报告,应用程序数据已被删除。当我搜索它时,我得到了这个 <a href="https://developer.apple.com/library/ios/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html" rel="noreferrer noopener nofollow">Apple Doc</a> .据此,DocumentsDirectory 应该是存储用户/应用程序数据的理想场所。 </p>

<blockquote>
<p>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.</p>
</blockquote>

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

<blockquote>
<p>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.</p>
</blockquote>

<p>存放它的理想位置应该是什么。 </p>

<p>编辑:</p>

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

<p>其次,我也想给 iTunes 分享功能。所以只有特定的文件必须存储在 DocumentsDirectory 中。有些文件永远不能公开,有些文件必须共享。存储文件的理想方式应该是什么。</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>对您希望通过 iTunes 共享的文件使用 <code>Documents</code> (<code>NSDocumentDirectory</code>)。</p>

<p>将<code>Application Support</code> (<code>NSApplicationSupportDirectory</code>) 用于您希望对用户隐藏但仍被备份且不会被操作系统删除的文件。</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 在IOS中存储应用程序数据的正确位置,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/47835808/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/47835808/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 在IOS中存储应用程序数据的正确位置