我遇到的一件非常令人沮丧的事情是无法同时打印到多台 AirPrint 打印机。不要将这与将多个项目打印到 1 台打印机相混淆。
示例:
我们有 3 台 AirPrint 打印机。
每台打印机都需要打印出一些东西……一个接一个。
如果您已经获得了 UIPrinter 对象,则可以调用:
- (BOOL)printToPrinter:(UIPrinter *)printer
completionHandler:(UIPrintInteractionCompletionHandler)completion;
在完成方法中,正常的过程是在完成方法中触发下一个作业,如下所示:
- (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.
}
}