OGeek|极客世界-中国程序员成长平台

标题: ios - 打印后删除文件 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 00:48
标题: ios - 打印后删除文件

我试图在打印后删除一个文件,但没有成功。

实际上,我需要打印一个临时生成的 PDF(带有文本和图像),然后,当打印过程完成后,我想将其删除。

目前 PDF 保存在 Documents 目录中。将其保存在 Temp 文件夹中是个好主意吗?但无论如何我都必须删除它。 我还有一个 tableView 显示用户保存的 PDF,所以我只需要显示那些(而不是那些 临时生成的)

我尝试过使用 UIPrinterInteractionController 的委托(delegate)方法,但没有任何运气。

-(void)printInteractionControllerDidDismissPrinterOptionsUIPrintInteractionController *)printInteractionController{
    NSError *error;
    NSFileManager *fileMgr = [NSFileManager defaultManager];
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *filePath = [documentsDirectory
                          stringByAppendingPathComponent:[NSString stringWithFormat"%@",PDFNameString]];
    if ([fileMgr removeItemAtPath:filePath error:&error] != YES)
    {   UIAlertView *alert = [[[UIAlertView alloc] initWithTitle"Error" message:[NSString stringWithFormat:NSLocalizedString(@"UnableToDeleteFile", @"Unable to delete file: %@"),[error localizedDescription]] delegate:self cancelButtonTitle"OK" otherButtonTitles:nil, nil] autorelease];
        [alert show];
    }

    NSLog(@"Dismissed");
}

仅当打印选项 View 离开“发送到打印机..” View 时,警报 View 才会弹出。 它甚至没有删除文件,它说

Cocoa 错误代码 4.

有谁知道打印完成后我可以使用什么方法来删除文件?

编辑

如果文件存在,我 NSLog'd,但它不存在。这怎么可能?



Best Answer-推荐答案


尝试 (void)printInteractionControllerDidFinishJobUIPrintInteractionController *)printInteractionController。

http://developer.apple.com/library/ios/ipad/#documentation/uikit/reference/UIPrintInteractionControllerDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intf/UIPrintInteractionControllerDelegate

关于ios - 打印后删除文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14671771/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4