Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a working UIPrinter object from Url for dialogue-free printing

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.

like image 734
RobinC Avatar asked Jan 05 '16 00:01

RobinC


1 Answers

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.

like image 127
mikesl Avatar answered Oct 11 '22 09:10

mikesl