我有一个简单的 iOS 应用程序,可以将收据打印到 STAR-TSP650II AirPrint 打印机。打印成功,但我需要将作业打印在 1 页上,因为它是收据......并且打印机能够这样做。AirPrint 有 2 个委托方法,它们是:
- (CGFloat)printInteractionController:(UIPrintInteractionController *)printInteractionController
cutLengthForPaper:(UIPrintPaper *)paper;
- (UIPrinterCutterBehavior)printInteractionController:(UIPrintInteractionController *)printInteractionController
chooseCutterBehavior:(NSArray *)availableBehaviors;
我无法调用这些方法。我尝试在方法中放置断点和日志以查看它们是否被调用,但没有。这是我的代码:
#pragma mark - Print:
- (void)printReceipt:(UIPrinter *)printer {
NSURL *receiptURL = [NSURL URLWithString:@"https://myurl.com/printer"];
UIPrintInteractionController *controller = [UIPrintInteractionController sharedPrintController];
[controller setDelegate:self];
[controller setPrintInfo:[UIPrintInfo printInfo]];
[controller setPrintingItem:receiptURL];
// contact:
[printer contactPrinter:^(BOOL available) {
// print:
[controller printToPrinter:printer completionHandler:^(UIPrintInteractionController * _Nonnull printInteractionController, BOOL completed, NSError * _Nullable error) {
}];
}];
}
- (CGFloat)printInteractionController:(UIPrintInteractionController *)printInteractionController cutLengthForPaper:(UIPrintPaper *)paper {
NSLog(@"this never gets called.");
return CGFLOAT_MAX;
}
- (UIPrinterCutterBehavior)printInteractionController:(UIPrintInteractionController *)printInteractionController chooseCutterBehavior:(NSArray *)availableBehaviors {
NSLog(@"this never gets called either.");
return UIPrinterCutterBehaviorCutAfterEachJob;
}