如何在我的应用程序的收件箱文件夹中删除导入的文件?

时间:2013-07-11 19:28:21

标签: ios file import delete-file

如何删除Open in我的应用功能导入的文件? 当我在我的应用程序中打开一些像PDF这样的文件时,我注意到我的应用程序大小增长了。看来是这样,那些文件将被复制到我的应用程序,我该如何找到并删除它们?

3 个答案:

答案 0 :(得分:3)

我明白了!这些文件存储在名为“收件箱”的文件夹的子文件夹中。你需要在那里删除它们。这是代码:

    NSString *fileName = @"afile.png";
    NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    NSString *inboxDirectory = [documentsDirectory stringByAppendingPathComponent:@"Inbox"];
    NSString *filePath = [inboxDirectory stringByAppendingPathComponent:fileName];
    NSError *error;
    BOOL success = [fileManager removeItemAtPath:filePath error:&error];
    if (!success) {
       NSLog(@"error occured during removing the file");
    }

答案 1 :(得分:0)

尝试启用itunes文件共享(http://www.raywenderlich.com/1948/how-integrate-itunes-file-sharing-with-your-ios-app),您可能会看到所有文件。

答案 2 :(得分:0)

在我看来,手动搜索收件箱并不是一个很好的做法。如果我有文件发送到我的应用程序,我在处理完它们之后删除它们,或者我以后需要它们,我将它们移动到cache / temp目录以防止iCloud备份它们。

func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {
    processUrl(url)
    removeFileAt(url)

    return true
}