我有一个简单的iOS应用程序,可将收据打印到STAR-TSP650II AirPrint打印机上。打印成功,但是我需要将作业打印在一页上,因为它是收据。打印机可以这样做。 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;
}
答案 0 :(得分:2)
我找到了问题的答案。
必须是未正确配置AirPrint打印机的STAR。
他们有2个iOS SDK; Standard和Legacy .. Legacy SDK具有剪纸所需的所有功能。如果遇到这种情况,请查看制造商是否有用于AirPrint的SDK。
答案 1 :(得分:-1)
您在其中编写了协议/委托方法的类/控制器,请尝试
[self setDelegate:controller];
并告诉我它是否不起作用。