在iOS应用中管理Documents/Inbox文件夹的好方法 [英] Good way to manage the Documents/Inbox folder in an iOS app

查看:705
本文介绍了在iOS应用中管理Documents/Inbox文件夹的好方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当文档交互系统将文件传递到iOS应用程序时,该文件的副本存储在应用程序捆绑包的Documents/Inbox文件夹中.应用程序处理完文件后,显然需要从Documents/Inbox中删除文件,否则文件夹将继续增长并浪费设备上的存储空间.

When a file is passed into an iOS application by the document interaction system, a copy of the file is stored in the application bundle's Documents/Inbox folder. After the application has processed the file, it obviously needs to remove the file from Documents/Inbox, otherwise the folder will continue to grow and waste storage on the device.

但是,我对这个简单的解决方案(A)感到不满意,因为我的应用需要与用户进行交互才能完成处理和删除文件的操作.如果用户在此交互期间暂停了该应用程序,并且随后在后台运行该应用程序,则该应用程序被杀死,下次该应用程序启动时,过时的文件将不会被删除.当然,我可以改进我的应用程序以适应这种情况,但是我怀疑总会有其他情况使我的文件夹"Documents/Inbox不干净".

I am uncomfortable with this simple solution (A), however, because my app needs to interact with the user before it can finish processing and removing the file. If the user suspends the app during this interaction period, and the app then gets killed while it is in the background, the stale file will not be removed when the app starts up the next time. Of course I can improve my app to cover this scenario, but I suspect that there will always be another border case that will leave me with an "unclean" Documents/Inbox folder.

因此,一个更好的解决方案(B)是在适当的时间(例如,当应用正常启动时,即不通过文档交互)删除Documents/Inbox文件夹.我对此仍然感到不舒服,因为我将访问一个文件系统路径,该路径的位置未在任何地方得到正式记录.例如,如果在将来的iOS版本中文档交互系统不再将文件放置在中,则我的应用程序将崩溃.

A preferrable solution (B) therefore would be to remove the Documents/Inbox folder at an appropriate time (e.g. when the app launches normally, i.e. not via document interaction). I am still uncomfortable with this because I would be accessing a filesystem path whose location is not officially documented anywhere. For instance, my app would break if in a future version of iOS the document interaction system no longer places files in Document/Inbox.

所以我的问题是:

  1. 您会推荐解决方案A还是B?
  2. 您使用其他方法吗?您能否概述应用程序如何管理Document/Inbox?
  3. 最后但并非最不重要:您是否知道涵盖该主题且我忽略了的Apple官方文档?

推荐答案

自从我问了这个问题以来,我已经实现了以下解决方案:

Since I have asked this question, I have implemented the following solution:

  • 我已经重新设计了我的应用程序,以便它现在可以立即处理通过文档交互传递给它的文件,而无需用户参与.除非应用程序在处理文件的过程中崩溃或被挂起并杀死,否则应该始终为我提供一个干净的Documents/Inbox.
  • 为了解决崩溃或暂停/死机的罕见情况,我的应用在正常启动时会删除Documents/Inbox文件夹(即,无需文档交互的目的).为此,必须对Documents/Inbox文件夹路径进行硬编码.
  • I have redesigned my app so that it now immediately processes a file handed over to it via documentation interaction, without involving the user at all. Unless the app crashes, or is suspended and killed, in the middle of processing the file, this should always leave me with a clean Documents/Inbox.
  • To cover the (rare) case of a crash or suspend/kill, my app removes the Documents/Inbox folder when it is launched normallly (i.e. without the purpose of document interaction). To achieve this the Documents/Inbox folder path is necessarily hardcoded.

以下是解决方案的想法:

Here are the thoughts that went into the solution:

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆