从 Url 创建一个工作 UIPrinter 对象以进行无对话打印 [英] Creating a working UIPrinter object from Url for dialogue-free printing
问题描述
场景:引导模式锁定的应用程序接受一些用户输入(姓名等)并打印出票证.用户无法选择打印机.
我计划的解决方案是保存打印机的 URL,我拥有并采用以下形式:
My planned solution was to save the URL of the printer, which I have and is in the form of:
ipp://<hostname>.local.:5001/<printername>
从这个存储的字符串构建 UIPrinter 对象:
To build the UIPrinter object from this stored string:
var printerURL = NSUrl.FromString(SettingsService.OptPrinterUrl);
var printer = UIPrinter.FromUrl(printerURL);
然后我打电话:
printer.ContactPrinter((available) => {
if (available) {
//
}
});
或
var printInterface = UIPrintInteractionController.SharedPrintController;
printInterface.PrintToPrinter(printer, (handler, completed, error) =>
{
if (!completed && error != null) {
UIAlertView alert = new UIAlertView("Guest Check-In App", "Print Error", null, "Ok", null);
alert.Show();
}
});
没有阳性结果.
但是,当使用从 UIPrinterPickerController 返回的 UIPrinter 对象(如下所示)时,一切正常.
However, when using a UIPrinter object returned from UIPrinterPickerController (as shown below) it all works.
var printerPicker = UIPrinterPickerController.FromPrinter(null);
printerPicker.PresentFromRect(new CGRect(0,0,100,100),this.View,true, delegate(UIPrinterPickerController handler, bool completed, NSError error) {
printer = printerPicker.SelectedPrinter;
});
我什至尝试从 PrinterPicker 获取 UIPrinter 对象,并尝试使用从 PrinterPicker 获取的 UIPrinter 对象中的 url 使用 UIPrinter.FromUrl 构建一个新的 UIPrinter.
I have even tried getting the UIPrinter object from PrinterPicker, and trying to build a new UIPrinter with UIPrinter.FromUrl using the url from the UIPrinter object taken from PrinterPicker.
我只能创建一个可以工作的 UIPrinter 对象,而没有直接使用 UIPrinterPickerController 中的对象,如下所示:
I was only able to create a working UIPrinter object without directly using the one from UIPrinterPickerController like so:
var printerPicker = UIPrinterPickerController.FromPrinter(null);
printerPicker.PresentFromRect(new CGRect(0,0,100,100),this.View,true, delegate(UIPrinterPickerController handler, bool completed, NSError error) {
printerPickerPrinter = printerPicker.SelectedPrinter;
});
var printer = (UIPrinter)UIPrinter.FromObject(printerPickerPrinter);
总结我需要的是一种记住"打印机的方法,并使用该打印机在 xamarin 构建的 iOS 应用程序中自动打印.
Summary What I need is a way to 'remember' a printer, and use that printer to print automatically in a xamarin-built iOS app.
推荐答案
这是一个 iOS 错误.我向 Apple Bug Reporter (47180997) 报告,他们给了我一个蹩脚的回复:
This is an iOS bug. I reported to Apple Bug Reporter (47180997) and they gave me a lame response:
Linux 上的共享打印机不适用于此 contactPrinter 方法.它要求成功返回打印机属性.即使其他部分出现故障,我们仍然经常发送打印作业.
Shared printers on Linux will not work with this contactPrinter method. It requires that the printer attributes are returned successfully. We often still send a print job even if the other parts fail.
要使这些方法正常工作,服务器必须是获得许可且正确实施的 AirPrint 服务器.在某处运行 CUPS 是不够的.
For these methods to work properly, the server has to be a licensed and correctly implemented AirPrint server. CUPS running somewhere isn’t enough.
这篇关于从 Url 创建一个工作 UIPrinter 对象以进行无对话打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!