7

我正在开发一个 iPad/iPhone 应用程序,该应用程序要求我在完成交易时在网络打印机上打印收据。我已经设法让 airprint 功能在某种程度上发挥作用,因为我可以让 UIPrintInteractionController 弹出框正确显示,单击“打印”按钮,然后在打印机模拟器中查看结果。由于我的应用程序的要求,我希望跳过弹出步骤并在我关闭交易时自动打印收据。换句话说,是否可以将打印作业发送到预先指定的网络打印机而无需添加额外的按钮单击?我是否需要尝试扩展 UIPrintInteractionController 类?如果是这样,有没有人对这种方法感到幸运?

任何其他替代建议也会很棒。

4

3 回答 3

1

使用该类无法做到这一点UIPrintInteractionController,它旨在为用户提供标准打印选项,并且没有应用商店安全的方法来解决这个问题。

于 2012-02-25T20:39:18.127 回答
0

尝试这个

  - (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);
             }
         }];
    }
}
}
于 2015-08-09T15:30:59.473 回答
-1

有一种方法

#import <BRPtouchPrinterKit/BRPtouchPrinterKit.h> 

BRPtouchPrinterKit 是打印机 Brother 的框架,更多信息在这里http://www.brother.com/product/dev/mobile/ios/

是专门针对此类打印机的 SDK

于 2015-08-09T14:19:12.607 回答