iOS 打印不允许 UIPrintInteractionController 出现 [英] iOS print without allowing UIPrintInteractionController to appear

查看:33
本文介绍了iOS 打印不允许 UIPrintInteractionController 出现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为客户研究一个潜在的应用程序,但我遇到了一个无法找到答案的问题.我想做的是自动打印,而不显示 UIPrintInteractionController.我应该指出的重要一点是,它不会成为生产应用程序.我知道否则这可能会侵犯用户的隐私,未经用户同意而直接打印,但这同样不会是 App Store 上的公共应用程序.我发现的一款似乎能够做到这一点的应用程序是 Printer Pro.系统提示用户打印测试页,打印页面时 UIPrintInteractionController 不出现 - 这个应用程序在商店里,所以我假设有一种合法的方式来做到这一点.有人知道这是怎么做到的吗?

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 UIPrintInteractionController get displayed. An important point I should make is this will not be a production app. I know that otherwise this could violate the user's privacy to just print without the user's consent, but again this will not be a public app on the App Store. One app I found that seems to be able to this is Printer Pro. The user is prompted to print a test page, and the page prints without the UIPrintInteractionController appearing - this app is on the store, so I'm assuming there's a legal way to do it. Anyone know how this is done?

推荐答案

据我所知,如果不调用 UIPrintInteractionController 并显示系统打印对话框,就无法在 iOS7 中进行打印.

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

>

但是,iOS8 现在提供了直接打印到打印件而不显示对话框的规定.基本思想是您获得一个 UIPrinter 对象并将其与 UIPrintInteractionController 的新 -printToPrinter:completionHandler: 方法结合使用来打印不显示对话框.

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.

为您的打印机获取 UIPrinter 对象可以通过多种方式完成.

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

最直接的是使用新的UIPrinterPickerController.但这会显示一个对话框,因此不能满足您的需求.

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

另一种方法是使用 UIPrinter 方法通过 URL 创建打印机+ printerWithURL:.我不完全清楚如何获取此 URL,但它可能包含在打印机的 HTML 管理页面中.我相信您可以使用 Bonjour API 以编程方式获取它.更多信息在这里:

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 是一个服务发现 API,包括发现 IPP 打印机,这是 AirPrint 使用的协议.

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

至于在 iOS7 中,Printer Pro 应用程序如何能够在没有对话框的情况下进行打印,我猜他们是在非常低的级别(例如原始 HTTP 帖子等)与打印机进行交互.

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.).

这篇关于iOS 打印不允许 UIPrintInteractionController 出现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆