【问题标题】:iPad/iPhone -- printing directly to a network printer without airprint popoveriPad/iPhone -- 直接打印到网络打印机,没有 airprint popover
【发布时间】:2011-02-27 20:36:44
【问题描述】:

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

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

【问题讨论】:

  • 你找到解决这个问题的方法了吗?
  • 我也在寻找同样的功能。有没有人知道这个。
  • @Rajashekar 最后,你找到任何方法了吗?

标签: printing airprint


【解决方案1】:

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

【讨论】:

  • 有没有任何应用商店不安全的方法可以做到这一点?
【解决方案2】:

试试这个

  - (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);
             }
         }];
    }
}
}

【讨论】:

    【解决方案3】:

    有办法

    #import <BRPtouchPrinterKit/BRPtouchPrinterKit.h> 
    

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

    是专门针对这种打印机的 SDK

    【讨论】:

      猜你喜欢
      • 2012-11-02
      • 1970-01-01
      • 1970-01-01
      • 2011-06-24
      • 1970-01-01
      • 2017-04-21
      • 2012-05-28
      • 2011-04-13
      • 1970-01-01
      相关资源
      最近更新 更多