iosobjective-cxcodeairprintuiprintinteractioncntrler

UIPrintInteractionController printing to multiple AirPrint printers


One really frustrating thing i've came across, is the inability to print to multiple AirPrint printers at once. Don't get this confused with printing out multiple ITEMS to 1 printer.

Example:
We have 3 AirPrint printers.
Each printer needs something printing out.. one after the other.

If you've already got your UIPrinter object, you would call:

- (BOOL)printToPrinter:(UIPrinter *)printer 
 completionHandler:(UIPrintInteractionCompletionHandler)completion;

In the completion method, the normal process would be to fire the next job in the completion method like so:

- (void)printAllJobs

    //  let's use an example printer url:
    UIPrinter *printer = [[UIPrinter alloc] initWithURL:[NSURL URLWithString:@"ipps://mycomputer.:863/printers/label"]];

    //  get the printer interaction controller:
    UIPrintInteractionController *controller = [UIPrintInteractionController sharedPrintController];

    //  now print:
    [controller printToPrinter:printer completionHandler:^(UIPrintInteractionController * _Nonnull printInteractionController, BOOL completed, NSError * _Nullable error) {

        //  here.. you would check if the job is complete:
        if (completed) {

            //  print to the next printer:
            //  THIS METHOD GETS FIRED BUT DOESN'T ACTUALLY PRINT
            [self printToNextPrinter];

        }

    }

}

- (void)printToNextPrinter {

    //  create next printer:
    UIPrinter *nextPrinter = [[UIPrinter alloc] initWithURL:[NSURL URLWithString:@"ipps://mycomputer.:863/printers/roller"]];

    //  get controller:
    UIPrintInteractionController *controller = [UIPrintInteractionController sharedPrintController];

    //  print:
    [controller printToPrinter:printer completionHandler:^(UIPrintInteractionController * _Nonnull printInteractionController, BOOL completed, NSError * _Nullable error) {

        //  this never gets executed.

    }

}

Solution

  • What i've found out:
    There's one noticeable thing taking place when this happens; there is a UIAlertController presented on screen that says "Printing to.. xxx" - which shows the printing progress.

    Solution:
    The solution is to check every 2 seconds to see if there's an alert visible on screen.. if so, repeat the same method, if not then fire the next printing job. It seems like Apple doesn't allow background printing with no alerts, so this is the only way.. other than diving into CUPS which would be a mess.