I’m trying to delete a file after printing it without success.
Practically, I need to print a PDF which is temporary generated (with text and image), then, when the printing process is done, I’d like to remove it.
Currently the PDF is being saved in Documents directory. Is it a good idea to save it in Temp folder? But then I’d have to remove it anyways.
I also have a tableView which shows the PDF the user saved, so I need to show only those (and not those temporarily generated)
I’ve tried with UIPrinterInteractionController’s delegate methods, but without any luck.
-(void)printInteractionControllerDidDismissPrinterOptions:(UIPrintInteractionController *)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");
}
The alert view pops up just when the printing options view leaves place to “Sending to printer..” view.
It doesn’t even delete the file, it says
Cocoa error code 4.
Does anyone know what method can I use to remove a file when the printing process is done?
EDIT
I NSLog’d if the file existed, and it doesn’t. How is this possible?
Try (void)printInteractionControllerDidFinishJob:(UIPrintInteractionController *)printInteractionController instead.
http://developer.apple.com/library/ios/ipad/#documentation/uikit/reference/UIPrintInteractionControllerDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intf/UIPrintInteractionControllerDelegate