xcode 您是否需要从文档/收件箱中删除导入的文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16213226/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Do you need to delete imported files from Documents/Inbox?
提问by ngb
I've got an iOS app that imported files from an email attachment. I've noticed that once i'm finished with it it places the imported file into Documents/Inbox.
我有一个从电子邮件附件导入文件的 iOS 应用程序。我注意到一旦我完成它,它会将导入的文件放入文档/收件箱。
Should my app be deleting these files or does the OS eventually get around to clearing them out?
我的应用程序应该删除这些文件还是操作系统最终会开始清除它们?
if so, how? i've tried:
如果是这样,如何?我试过了:
[[NSFileManager defaultManager] removeItemAtPath:[self.url path] error:nil];
However it doesn't seem to reference the file in the inbox, even though self.url is the correct path to my import file.
但是它似乎没有引用收件箱中的文件,即使 self.url 是我的导入文件的正确路径。
采纳答案by B.S.
System does not clear imported files, so you should clear them manually when it is necessary, but not to delete the Documents directory.
系统不会清除导入的文件,因此您需要在必要时手动清除它们,但不要删除 Documents 目录。
How to clear the NSDocumentsDirectory
you can find here
如何清除NSDocumentsDirectory
您可以在这里找到的
If you want to delete files from the inbox use the same code adding
如果要从收件箱中删除文件,请使用相同的代码添加
...
NSString *path = [NSString stringWithFormat:@"%@/Inbox", documentsDirectory ];
NSArray *directoryContents = [fileMgr contentsOfDirectoryAtPath:error:&error];
...
Read the reference
阅读参考资料
From 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.
使用此目录访问外部实体要求您的应用打开的文件。具体来说,Mail 程序会将与您的应用程序关联的电子邮件附件放在此目录中;文档交互控制器也可以在其中放置文件。
您的应用程序可以读取和删除此目录中的文件,但不能创建新文件或写入现有文件。如果用户尝试编辑此目录中的文件,您的应用程序必须在进行任何更改之前将其移出目录。
此目录的内容由 iTunes 备份。