iphone - 使用 UIPrintInteractionController 打印 PDF ios 5 有效,但在 ios 6 中不起作用并使我的应用程序崩溃

标签 iphone objective-c ios6 airprint

我在使用 UIPrintInteractionController 时遇到问题 我发送了一个 pdf 来打印,当我按下打印按钮将文件发送到打印机并工作时,我使用带有 ios 5 的设备发送了一个问题。但是当我在装有 ios 6 的设备上进行测试时,我无法正常工作并导致应用程序崩溃。

当 UIPrintInteractionController 的 View 出现在 ios 6 上时,这是日志:

Save\032in\032folder\032Aptana\032Rubles._ipp._tcp.local.:
   Get-Printer-Attributes failed:    Undefined error: 0
No document-format-supported attribute found or no supported formats
   found.
No media-col-database found in response from printer.
Defaulting to generic media size values.
No print-quality-supported attribute found.  Defaulting to normal
   quality.
No sides-supported attribute found.  Defaulting to single-sided.

这是我的代码:(self.myPDF 是一个 NMutableSData 类型)

UIPrintInteractionController *controller = [UIPrintInteractionController sharedPrintController];

if  (controller && [UIPrintInteractionController canPrintData: self.myPDF] ) {



UIPrintInfo *printInfo = [UIPrintInfo printInfo];
    printInfo.outputType = UIPrintInfoOutputGeneral;
    printInfo.jobName = [NSString stringWithFormat:@"Coupon"];
    printInfo.orientation = UIPrintInfoOrientationPortrait;
printInfo.duplex = UIPrintInfoDuplexLongEdge;

    controller.printInfo = printInfo;
controller.showsPageRange =NO;

    controller.printingItem = self.myPDF;

    void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) =
    ^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
        if (!completed && error) {

            UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"Error." 
                                                         message:[NSString stringWithFormat:NSLocalizedString(@"An error occured while printing: %@", @"Printing error"), error]
                                                        delegate:nil 
                                               cancelButtonTitle:@"OK" 
                                               otherButtonTitles:nil, nil];

            [av show];
            [av release];
        }
    };

    [controller presentAnimated:YES completionHandler:completionHandler];
}

我没有支持 AirPrint 的打印机,但我使用了 handyPrint。 注意:在 iOS 6 上,它可以使用 handyPrint 通过 safari 进行打印。

谁知道哪里出了问题? =(

最佳答案

使用 Xcode 附带的 AirPrint 打印机模拟器对其进行测试。这个问题很可能出在 handyPrint 不支持 AirPrint 的新功能上。

关于iphone - 使用 UIPrintInteractionController 打印 PDF ios 5 有效,但在 ios 6 中不起作用并使我的应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17218689/

相关文章:

ios - 如何将登录添加到我的 iOS PDF 阅读器应用程序?

iphone - 了解GCD block 中[NSData dataWithContentsOfURL:URL]的行为

iphone - 触摸时旋转 View

ios - 如果设备版本为 iOS 8,则删除启动屏幕

iphone - 我们可以在 iPhone 设备上自动安装任何 .deb/.ipa 文件吗?

objective-c - 什么需要子类化 UIView 而不是创建我们自己的 View 并将其添加到

iphone - 如何在线程中执行 GUI 操作 - IOS

c++ - 合并两个数组中的唯一元素

facebook - 通过新的iOS6社交框架查询Facebook用户数据

ios - 想在服务器上保存申请状态