从同一网络但不同子网的iOS应用程序访问wifi打印机

时间:2015-08-26 14:42:30

标签: ios printing wifi subnet uiprintinteractioncntrler

在我的项目中有一个打印选项,我们使用以下代码打印一个简单的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的另一个子网上。我如何使这项工作?

1 个答案:

答案 0 :(得分:0)

无需更改代码UIPrintInteractionController中的任何内容,如果打印机将位于同一网络中,则可以发现UIPrintInteractionController,并且从弹出窗口中您可以选择打印机