Scenario: Guided-Mode locked app accepts some user input (name, etc) and prints them out a ticket. The user cannot be able choose a printer.
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>
To build the UIPrinter object from this stored string:
var printerURL = NSUrl.FromString(SettingsService.OptPrinterUrl);
var printer = UIPrinter.FromUrl(printerURL);
I then call:
printer.ContactPrinter((available) => {
if (available) {
//
}
});
OR
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();
}
});
Without positive result.
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;
});
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.
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);
Summary What I need is a way to 'remember' a printer, and use that printer to print automatically in a xamarin-built iOS app.
This is an iOS bug. I reported to Apple Bug Reporter (47180997) and they gave me a lame response:
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.
For these methods to work properly, the server has to be a licensed and correctly implemented AirPrint server. CUPS running somewhere isn’t enough.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With