0

在我的项目中有一个打印选项,我们使用以下代码打印一个简单的 pdf 文件:

UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController];

if  (pic && [UIPrintInteractionController canPrintData: self.myPDFData] ) {
    pic.delegate = self;
    UIPrintInfo *printInfo = [UIPrintInfo printInfo];
    printInfo.outputType = UIPrintInfoOutputGeneral;
    printInfo.jobName = @"PrintPdf";
    printInfo.duplex = UIPrintInfoDuplexLongEdge;
    pic.printInfo = printInfo;
    pic.showsPageRange = YES;
    pic.printingItem = self.myPDFData;     
    void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) =

    ^(UIPrintInteractionController *pic, BOOL completed, NSError *error) {
        if (!completed && error)
            NSLog(@"FAILED! due to error in domain %@ with error code %ld",
                  error.domain, (long)error.code);
    };
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
        [pic presentFromRect:self.printButton.frame inView:self.view animated:YES completionHandler:^(UIPrintInteractionController *printInteractionController, BOOL completed, NSError *error) {
        }];
    } else {
        [pic presentAnimated:YES completionHandler:completionHandler];
    }
}

当我在打印机模拟器中对其进行测试时,它工作正常。我的要求是打印机可能在同一个 wifi 的另一个子网上。我该如何进行这项工作?

4

1 回答 1

0

无需更改代码UIPrintInteractionController中的任何内容,如果打印机将在同一个网络中,那么它将可以UIPrintInteractionController在弹出窗口中发现,您将能够选择打印机。

于 2015-08-26T14:59:06.733 回答