UIPrinterCutterBehavior delegate method never called

250 views Asked by At

I have a simple iOS application that prints out receipts to a STAR-TSP650II AirPrint printer. The prints are successful, but I need the jobs to be printed on 1 page, seeing as it's a receipt.. and the printer is capable of doing so. There are 2 delegate methods for AirPrint which are:

- (CGFloat)printInteractionController:(UIPrintInteractionController *)printInteractionController 
                cutLengthForPaper:(UIPrintPaper *)paper;
- (UIPrinterCutterBehavior)printInteractionController:(UIPrintInteractionController *)printInteractionController 
                             chooseCutterBehavior:(NSArray *)availableBehaviors;

I can't get these methods to be called. I've tried putting breakpoints and logs in the methods to see if they're called, but no. Here is my code:

#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;
} 
2

There are 2 answers

5
Declan Land On BEST ANSWER

I found an answer to my question.

It must be STAR that haven't configured their printer with AirPrint properly.

They have 2 iOS SDK's; Standard and Legacy.. the Legacy SDK has all the functions I need to cut the paper. If you come across something like this, see if the manufacturer has an SDK for AirPrint.

1
Abid Mehmood On

The class/Controller in which you wrote protocol/delegate method, try this

[self setDelegate:controller];

and tell me if its not working.