我在 Xamarin 中使用 iOs 默认 PrinterToPrint 进行打印,但没有显示选择打印机的对话框,但它也显示了一个对话框,显示打印到 [PRINTER NAME]。无论如何也可以隐藏对话框。喜欢完整的静音打印功能?
我不可能,但我见过一些应用程序可以做到这一点,我不确定它们是否使用相同的功能。
提前致谢。
最佳答案
更新:UIPrinterPickerController
来自 UIKit
因此,无法将“打印”进程推到后台并关闭主 UI 线程。
在当前UIPrintInteractionController.PrintToPrinter
实现(目前最高到 iOS 10.3 B4)没有公开的方法来禁用打印进度(连接、准备等)警报/对话框(带取消按钮)或修改其外观。
此接口(interface)是使用 AirPrint
的高级包装器因此,较低级别的 Internet 打印协议(protocol) (IPP) 可以执行实际打印、打印机上的作业队列监控等...... IPP 目前并未作为 iOS 中的公开可用框架公开......
允许后台打印的程序未使用 UIPrintInteractionController
进行打印。大多数人使用UIPrinterPickerController
获取 UIPrinter
用户选择,但随后使用 UIPrinter.Url.AbsoluteUrl
通过 HTTP/HTTPS Post/Get 直接与打印机“对话”。根据所使用的打印机,基于 TCP 的套接字也是与 IPP 甚至 USB/串行直接连接打印机的一个选项。
回复:https://en.wikipedia.org/wiki/Internet_Printing_Protocol
原来的:
选择打印机:
if (allowUserToSelectDifferentPrinter || printerUrl == null)
{
UIPrinter uiPrinter = printerUrl != null ? null as UIPrinter : UIPrinter.FromUrl(new NSUrl(printerUrl));
var uiPrinterPickerController = UIPrinterPickerController.FromPrinter(uiPrinter);
uiPrinterPickerController.Present(true, (printerPickerController, userDidSelect, error) =>
{
if (userDidSelect)
{
uiPrinter = uiPrinterPickerController?.SelectedPrinter;
printerUrl = uiPrinter.Url.AbsoluteUrl.ToString();
Console.WriteLine($"Save this UIPrinter's Url string for later use: {printerUrl}");
}
});
}
使用 UIPrintInteractionController
打印与现有的 UIPrinter
:if (printerUrl != null)
{
// re-create a UIPrinter from a saved NSUrl string
var uiPrinter = UIPrinter.FromUrl(new NSUrl(printerUrl));
var printer = UIPrintInteractionController.SharedPrintController;
printer.ShowsPageRange = false;
printer.ShowsNumberOfCopies = false;
printer.ShowsPaperSelectionForLoadedPapers = false;
var printInfo = UIPrintInfo.PrintInfo;
printInfo.OutputType = UIPrintInfoOutputType.General;
printInfo.JobName = "StackOverflow Print Job";
var textFormatter = new UISimpleTextPrintFormatter("StackOverflow Rocks")
{
StartPage = 0,
ContentInsets = new UIEdgeInsets(72, 72, 72, 72),
MaximumContentWidth = 6 * 72,
};
printer.Delegate = new PrintInteractionControllerDelegate();
printer.PrintFormatter = textFormatter;
printer.PrintToPrinter(uiPrinter, (printInteractionController, completed, error) =>
{
if ((completed && error != null))
{
Console.WriteLine($"Print Error: {error.Code}:{error.Description}");
PresentViewController(
UIAlertController.Create("Print Error", "Code: {error.Code} Description: {error.Description}", UIAlertControllerStyle.ActionSheet),
true, () => { });
}
printInfo?.Dispose();
uiPrinter?.Dispose();
uiPrinter.
});
}
else
{
Console.WriteLine("User has not selected a printer...printing disabled");
}
关于ios - PrinterToPrint 不显示打印作业进度对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42562947/