7

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.

RobinC
  • 71
  • 3
  • http://stackoverflow.com/questions/6828082/printing-without-uiprintinteractioncontroller – Jason Jan 05 '16 at 02:17
  • https://forums.xamarin.com/discussion/32932/print-directly-to-printer-without-presenting-print-dialog-printtoprinter http://stackoverflow.com/questions/29925387/skipping-the-printing-ui-in-ios-8 http://stackoverflow.com/questions/13145724/ios-print-without-allowing-uiprintinteractioncontroller-to-appear – RobinC Jan 05 '16 at 05:59
  • https://www.reddit.com/r/swift/comments/2x0nln/uiprinter_fromurl/ – RobinC Jan 05 '16 at 06:07
  • In Jasons comment I watched a video linked by another user, `https://developer.apple.com/videos/play/wwdc2014-718/` is relevant from 32:50 to 38:10. at 35:35, it states the app is responsible for saving the URL. Presenter says “You’ll instantiate a new UIPrinter with just this URL you have saved”. at 36:50 states that UIPrintInteractionController.printToPrinter supports UIPrinter either from UIPrinterPickerController or a UIPrinter instantiated with a URL. All it does is describe what I've done. And assume it works. I'm beginning to think the fact that it doesn't is a bug with xamarin. – RobinC Jan 05 '16 at 06:35
  • Fair enough, then it sounds like you should file a bug: bugzilla.xamarin.com – Jason Jan 05 '16 at 12:06
  • Seeing the same issue in Xcode without Xamarin. I think it's an iOS bug. – mikesl Jan 10 '19 at 17:36
  • I opened bug report with apple radar: 47180997. Please open separate bug for whoever has this issue and you can reference my bug id. – mikesl Jan 10 '19 at 18:05

1 Answers1

1

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.

Community
  • 1
  • 1
mikesl
  • 2,133
  • 20
  • 25