我在自定义 QLPreviewController 的 navigationItem 中添加了一个操作按钮。当点击操作按钮时,我会呈现一个 UIPrintInteractionController。我正在从我的应用程序的 Documents 目录中获取文件。预览它们时没有问题。但是当我通过点击操作按钮打印相同的文件时,[UIPrintInteractionController canPrintData:data] 返回 false。但是,如果文件位于我的应用程序根目录内,它就可以工作。
下面是代码,当点击操作按钮时执行。
- (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];
}
}
}
我无法想象这个问题。请帮忙...