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>"];