【问题标题】:How can I delete a imported file in my inbox folder in my app?如何在我的应用程序的收件箱文件夹中删除导入的文件?
【发布时间】:2013-07-11 19:28:21
【问题描述】:

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

【问题讨论】:

    标签: ios file import delete-file


    【解决方案1】:

    我想通了!这些文件存储在名为“收件箱”的文档文件夹的子文件夹中。您需要在那里删除它们。代码如下:

        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");
        }
    

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

        【解决方案3】:

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2019-10-31
          • 1970-01-01
          • 1970-01-01
          • 2014-04-09
          • 1970-01-01
          • 2012-03-01
          • 2012-01-09
          • 2019-02-28
          相关资源
          最近更新 更多