UIPrinterPickerController, UIPrintInteractionController, UIPrinter do not work on macOS Catalyst

On iOS emulator :
  • I can select a printer from the UIPrinterPickerController dialog and retrieve the printer

  • I can connect to that printer with UIPrinter.contactPrinter

  • I can send multiple jobs to that printer silently (no dialog) with UIPrintInteractionController

Same code or any similar code on macOS Catalyst :
  • Absolutely nothing is working. I see nothing, no dialog, no errors in the log.

Post not yet marked as solved Up vote post of Lord Rubymace Down vote post of Lord Rubymace
2.5k views

Replies

Same problem here. I guess Apple forgot about Catalyst printing functionality. Our office app does not print on macOS, but it does on iPhone???

On Mac Catalyst, always use UIPrintInteractionController to present a print dialog. This is bridged to the Mac print dialog.

The Mac print dialog already includes its own Mac-style UI to select the printer, so showing a separate printer picker dialog is not necessary.

In fact, the UIPrinter and UIPrinterPickerController APIs are only shims, and they are mostly ignored in Catalyst. Do not attempt to print silently to a UIPrinter instance.

Apple please implement in Mac Catalyst apps like with iOS… There are proper use cases where the user has already selected a printer and we don’t want to keep asking for which printer for subsequent prints. That being said, we need to be able to print silently to UIPrinter with a printer that was already captured/selected by the user. Please implement as a lot of us developers need this feature like in iOS!

Make sure you have "Printing" turning on in "App Sandbox".

Probably still need UIPrintInteractionController, though.

Yes my Printing is allowed in app sandbox.

Any update on this? Unfortunately seems that is not yet working....

Note that my App, built 2 years ago, does print plaintext OK, on Mac Catalyst and iOS. It’s only when re-compiled today using Xcode 15.2 on Sonoma that printing fails, on Mac Cat and iOS BTW.

On print failure this is what my App's traceback looks like:

 #0	0x00000001b070ee34 in _UITextViewEnablingCompatibilityMode ()

 #16	0x000000022a343348 in -[UIPrintInteractionController presentFromRect:inView:animated:completionHandler:] ()

 #17	0x0000000102845518 in __23-[Common printTextView]_block_invoke_2 at /Users/sol/Private/Developer/ ...

Poking around further I see this:

0x1b070eec0 <+140>: add x3, x3, #0x286 ; "UITextView %{public}p is switching to TextKit 1 compatibility mode because its layoutManager was accessed. Break on %{public}s to debug.”

This was a trigger, because 2 years ago when the App last went on the App Store I found that I could only print plaintext files, not HTML, so I settled on using as the print formatter an instance of UISimpleTextPrintFormatter.

So I just switched to UIMarkupTextPrintFormatter, and, amazingly, it worked, no crash. Of course plaintext files look pretty ugly, but HTML now works and looks great. This hack for plaintext works for me, YMMV:

    printText = [printText stringByReplacingOccurrencesOfString:@"\n" withString:@"<br>"];