我添加了一个动作按钮到我的自定义QLPreviewController的navigationItem。当点击动作按钮时,我呈现一个UIPrintInteractionController。 我从我的应用程序的文档目录中获取文件。预览时没有问题。但是当我通过点击操作按钮打印相同的文件时,[UIPrintInteractionController canPrintData:data]返回false。但它的工作原理是,如果文件在我的应用程序根目录中。UIPrintInteractionController打印问题
下面是代码,点击操作按钮时执行。
- (void)tappedPrintButton:(id) sender {
UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController];
NSURL *fileURL = (NSURL *)[self currentPreviewItem];
NSData *data = [NSData dataWithContentsOfURL:fileURL];
if (pic && [UIPrintInteractionController canPrintData:data]) {
pic.delegate = self;
UIPrintInfo *printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputGeneral;
printInfo.jobName = [(NSURL *)[self.files objectAtIndex:0] lastPathComponent];
printInfo.duplex = UIPrintInfoDuplexLongEdge;
pic.printInfo = printInfo;
pic.showsPageRange = YES;
pic.printingItem = data;
void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) =
^(UIPrintInteractionController *pic, BOOL completed, NSError *error) {
if (!completed && error)
NSLog(@"FAILED! due to error in domain %@ with error code %u",
error.domain, error.code);
};
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
[pic presentFromBarButtonItem:self.myActionBarButton animated:YES
completionHandler:completionHandler];
} else {
[pic presentAnimated:YES completionHandler:completionHandler];
}
}
}
我无法想象这个问题。请帮助...