iPad/iPhone -- printing directly to a network printer without airprint popover
Asked Answered
F

3

7

I've developing an iPad/iPhone application that requires that I print out a receipt on a network printer when I finish a transaction. I've managed to get airprint functionality working to some extent in that I can get the UIPrintInteractionController popover to appear appropriately, click the "Print" button and then view the results in the Printer Simulator. Because of the requirements of my application, I'm hoping to skip the popover step and automatically print the receipt when I close the transaction. In other words, is it possible to send a print job to a pre-specified network printer without having to add the extra button click? Do I need to try to extend the UIPrintInteractionController class? If so, has anyone had luck with this approach?

Any other alternate recommendations would be great as well.

Fasano answered 27/2, 2011 at 20:36 Comment(3)
Have you found any solution for this question?Bedwell
i am also looking for the same kind of functionality. has anyone figured this out.Panther
@Panther at last, did you find any method to do this?Chirrupy
L
1

There is no way to do this using the UIPrintInteractionController class, it is designed to present the user with standard print options, and there is no app store safe way of getting around this.

Launcher answered 25/2, 2012 at 20:39 Comment(1)
and is there any app store unsafe way to do this?Chirrupy
G
0

try this

  - (IBAction)Print:(id)sender {
    [self searchForPrinters];
   }
 - (void) searchForPrinters
  {

  if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_7_1)
  {
         UIPrinterPickerController *printPicker = [UIPrinterPickerController   printerPickerControllerWithInitiallySelectedPrinter:nil];
    [printPicker presentAnimated:YES completionHandler:
     ^(UIPrinterPickerController *printerPicker, BOOL userDidSelect,    NSError *error)
         {
         if (userDidSelect)
           {
             //User selected the item in the UIPrinterPickerController and got the printer details.

             [UIPrinterPickerController printerPickerControllerWithInitiallySelectedPrinter:printerPicker.selectedPrinter];

             //Here you will get the printer and printer details.ie,
             // printerPicker.selectedPrinter, printerPicker.selectedPrinter.displayName, printerPicker.selectedPrinter.URL etc. So you can display the printer name in your label text or button title.

             [btnSettingsPrint setTitle:printerPicker.selectedPrinter.displayName forState:UIControlStateNormal];

             NSURL *printerURL = printerPicker.selectedPrinter.URL;

         }
     }];
}
 }

 -(void)printYourItem :(NSData*)data
 {
 if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_7_1)
  {
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    UIPrinter *currentPrinterObj = [UIPrinter printerWithURL:[NSURL URLWithString:[defaults stringForKey:@"YouKeys"]]];

    UIPrintInteractionController *controller = [UIPrintInteractionController sharedPrintController];

    if(currentPrinterObj)
    {
        [controller printToPrinter:currentPrinterObj completionHandler:^(UIPrintInteractionController *printController, BOOL completed, NSError *error)
         {
             if(completed)
             {
             }
             else
             {
                 NSLog(@"FAILED! due to error in domain %@ with error code %u", error.domain, error.code);
             }
         }];
    }
}
}
Goodman answered 9/8, 2015 at 15:30 Comment(0)
G
-1

There is a way

#import <BRPtouchPrinterKit/BRPtouchPrinterKit.h> 

BRPtouchPrinterKit is a Framework for Printer Brother more info here http://www.brother.com/product/dev/mobile/ios/

Is a SDK especially for this type of printer

Goodman answered 9/8, 2015 at 14:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.