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.