iosprintingwifisubnetuiprintinteractioncntrler

Access wifi printer from iOS app in same network but different subnet


In my project there is a print option where we print a simple pdf file with following code:

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];
    }
}

It works fine when I have tested it in the Printer Simulator. My requirement is that the printer may be on another subnet of the same wifi. How do I make this work?


Solution

  • No need to change anything in the code UIPrintInteractionController, if the printer will be in the same network then it will be discoverable to UIPrintInteractionController and from the pop up you will be able to select the printer.