加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

iphone – 您需要从Documents / Inbox中删除导入的文件吗?

发布时间:2020-12-14 19:59:44 所属栏目:百科 来源:网络整理
导读:我有一个从电子邮件附件导入文件的iOS应用程序. 我注意到,一旦我完成它,它将导入的文件放入Documents / Inbox. 我的应用程序应该删除这些文件还是操作系统最终会清除它们? 如果是这样,怎么样?我试过了: [[NSFileManager defaultManager] removeItemAtPath
我有一个从电子邮件附件导入文件的iOS应用程序.
我注意到,一旦我完成它,它将导入的文件放入Documents / Inbox.

我的应用程序应该删除这些文件还是操作系统最终会清除它们?

如果是这样,怎么样?我试过了:

[[NSFileManager defaultManager] removeItemAtPath:[self.url path] error:nil];

但是它似乎没有引用收件箱中的文件,即使self.url是我的导入文件的正确路径.

解决方法

系统不会清除导入的文件,因此您应该在必要时手动清除它们,但不要删除Documents目录.

如何清除NSDocumentsDirectory,你可以找到here

如果要从收件箱中删除文件,请使用相同的代码添加

...
NSString *path = [NSString stringWithFormat:@"%@/Inbox",documentsDirectory ];
NSArray *directoryContents = [fileMgr contentsOfDirectoryAtPath:error:&error];
...

阅读reference

来自apple doc:

Use this directory to access files that your app was asked to open by
outside entities. Specifically,the Mail program places email
attachments associated with your app in this directory; document
interaction controllers may also place files in it.

Your app can read and delete files in this directory but cannot create new files or write to existing files. If the user tries to edit
a file in this directory,your app must silently move it out of the
directory before making any changes.

The contents of this directory are backed up by iTunes.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读