我添加了一個動作按鈕到我的自定義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];
}
}
}
我無法想象這個問題。請幫助...