iOS print without allowing UIPrintInteractionController to appear

前端 未结 2 604
抹茶落季
抹茶落季 2020-12-03 09:05

I am researching a potential app for a client, and I had a question I wasn\'t able to find the answer on. What I would like to do is print automatically, without having the

2条回答
  •  萌比男神i
    2020-12-03 09:32

    As far as I know it is not possible to print in iOS7 without invoking the UIPrintInteractionController and displaying the system print dialog.

    However, iOS8 now provides a provision for printing directly to a print without showing the dialog. The basic idea is that you obtain a UIPrinter object and use this in conjunction with the new - printToPrinter:completionHandler: method of the UIPrintInteractionController to print without showing the dialog.

    Obtaining the UIPrinter object for your printer can be accomplished in a couple of ways.

    The most straightforward is to use the new UIPrinterPickerController. But this would show a dialog and so doesn’t meet your needs.

    The alternative is to create a printer via its URL using the UIPrinter method + printerWithURL:. I’m not entirely clear how to obtain this URL but it may be contained in the printer’s HTML admin pages. And I believe you can obtain it programmatically using the Bonjour API. More info here:

    https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/NetServices/Introduction.html#//apple_ref/doc/uid/10000119i

    Bonjour is a service discovery API which includes discovery of IPP printers, which the is the protocol used by AirPrint.

    As for how the Printer Pro app is able to print without a dialog in iOS7, I would guess they are interacting with the printer at a very low level (e.g. raw HTTP posts, etc.).

提交回复
热议问题