Print dialogs for iOS in Xojo
For iOS you may miss the print dialogs in Xojo. For upcoming 24.2 version of MBS Xojo Plugins we have new classes for you: The UIPrinterPickerControllerMBS class allows to show a printer picker dialog to choose the printer. And the UIPrintInteractionControllerMBS allows to show a dialog for printing a PDF or image.
Pick Printer
First we want to pick a printer. Let's show the printer picker. If you like, you can set a few properties like the SelectedPrinter property to preselect a printer.
In the Completed event, you can react to the user's choice. Check the error property for an error and the userDidSelect property. If the userDidSelect property is true, the check the selectedPrinter property.
Print with dialog
Now let's print something. The UIPrintInfoMBS class allows you to set a few properties. Like we may ask for grayscale printing, duplex on the long edge and pre-pick a printer. We can also decide whether to show controls for orientation, number of copies and paper choice.
To print an elements, you assign it to the printingItem property. You can print pictures, image files or PDF documents here. If you have multiple PDF documents, you can call setPrintingItems() to pass multiple items to print.
Once you show the printing dialog, you may later see a Completed event called. Here the system tells you whether the job is completed and what error may have happened. We can lookup what printer was used and remember it for the next time.
Print without dialog
If you like to print directly to a printer on the local network for e.g. a receipt, you can use the UIPrintInteractionControllerMBS class with the printToPrinter method. Now you need the printer referenced with an UIPrinterMBS object based on the URL of the printer. This prints silently in the background and later calls the Completed event.
For all this controllers, please keep the references to them in a property of the current screen or a global one. If the controller object gets destroyed too early the dialog may not show at all or suddenly disappear.
Please try the 24.2 version of MBS Xojo iOS Plugin and see if this works for you. Please don't hesitate to contact us with your questions.