Printing iPad/iPhone--无需airprint popover即可直接在网络打印机上打印
我正在开发一个iPad/iPhone应用程序,它要求我在完成交易时在网络打印机上打印收据。我已经设法使airprint功能在某种程度上发挥作用,因为我可以使UIPrintInteractionController弹出框正确显示,单击“打印”按钮,然后在打印机模拟器中查看结果。由于我的应用程序的要求,我希望跳过popover步骤,在关闭交易时自动打印收据。换句话说,是否可以将打印作业发送到预先指定的网络打印机,而无需添加额外的按钮单击?我是否需要尝试扩展UIPrintInteractionController类?如果是的话,有没有人对这种方法感到幸运Printing iPad/iPhone--无需airprint popover即可直接在网络打印机上打印,printing,airprint,Printing,Airprint,我正在开发一个iPad/iPhone应用程序,它要求我在完成交易时在网络打印机上打印收据。我已经设法使airprint功能在某种程度上发挥作用,因为我可以使UIPrintInteractionController弹出框正确显示,单击“打印”按钮,然后在打印机模拟器中查看结果。由于我的应用程序的要求,我希望跳过popover步骤,在关闭交易时自动打印收据。换句话说,是否可以将打印作业发送到预先指定的网络打印机,而无需添加额外的按钮单击?我是否需要尝试扩展UIPrintInteractionCont
任何其他替代建议也很好。使用
UIPrintInteractionController
类无法做到这一点,它是为用户提供标准打印选项而设计的,没有app store安全的解决方法。有一种方法
#import <BRPtouchPrinterKit/BRPtouchPrinterKit.h>
#导入
BRPtouchPrinterKit是打印机兄弟的一个框架,这里有更多信息
是专门针对这种类型打印机的SDK试试这个
- (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);
}
}];
}
}
}
你找到这个问题的解决方案了吗?我也在寻找同样的功能。有人发现了吗?@Rajashekar最后,你找到了什么方法来做到这一点吗?有没有任何应用商店不安全的方法来做到这一点?