在 iOS 设备中创建 Bonjour AirPrint 服务
因此,我发现要作为打印机发布(宣布服务)到 iOS 设备,我使用 NSNetService 并将类型设置为 _ipp._tcp
。
但为了被识别为 AirPrint 打印机,要求包括:
- AirPrint 使用 IPP 进行打印管理。
- AirPrint 侦听 mDNS (Bonjour/Avahi) 以发现打印机。
- AirPrint 需要在
_ipp
公告中包含_universal
子类型,然后才会考虑列出打印机。 - AirPrint 需要一个额外的 TXT 记录“URF”,该记录必须存在且非空,然后才会考虑列出打印机。
- 虽然这种 URF 格式(见下文)似乎是 Apple 的未来选项,但当前所有支持 AirPrint 的应用程序似乎都以 PDF 形式发送打印数据。
- 当打印机受用户名/密码保护时,iTunes/AirPrint 守护程序将发送 TXT 记录“air=用户名,密码”。
所以我想弄清楚如何发布子类型并在 NSNetService 下发布 TXT 记录,但我无法做到这一点。有人有什么想法吗?
So I figured out that to publish (announce the service) to an iOS device as a printer, I use NSNetService and set the type to _ipp._tcp
.
But in order to be recognized as an AirPrint printer the requirements include:
- AirPrint uses IPP for print management.
- AirPrint listens to mDNS (Bonjour/Avahi) for printer discovery.
- AirPrint requires a
_universal
subtype to be present in the_ipp
announcement before it will consider listing the printer. - AirPrint requires an additional TXT record, "URF", to be present and non-empty before it will consider listing the printer.
- While this URF format (see below) appears to be a future option for Apple, all current AirPrint-enabled apps seem to send print data as PDF.
- When a printer is protected by a username/password, the iTunes/AirPrint daemon will send a TXT record "air=username,password".
So I am trying to figure out how to publish the subtype and publish the TXT record under NSNetService which I haven't been able to do. Anyone have any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于到目前为止您甚至没有显示代码的起点或存根,因此这里有一个不同的提示:您可以在本地 LAN/WLAN 中模拟有效的、工作的 AirPrint 服务公告,这将允许您的 iOS 客户端成功打印到现有打印机(AirPrint 或非 AirPrint)。
要求:装有 OS X 的 Mac。
一旦您开始工作,您现在可以使用 Wireshark 或 tcpdump 之类的工具来捕获网络上或空中的包并保存和分析它们。
然后开始编写您自己的应用程序并使其发出与模拟相同的包。
已知以下内容适用于 OS X Yosemite (10.10.x)。
假设,...
mymac
,192.168.111.111
,abcd
的共享打印机 (不需要需要支持 AirPrint!),并且DefaultAuthType none
放入/etc /cups/cupsd.conf
),...然后您可以使
abcd
队列可供 iOS 客户端使用。要测试这一点,只需在 Terminal.app 窗口中执行以下命令(注意,该命令不会返回 - 如果关闭 Terminal.app 窗口,该命令的效果将消失!):
如果有效(如应该),您可以轻松地编写一个脚本或 cron 作业,在每次 Mac 启动时执行此命令(并让它在后台运行)。这留给读者作为练习。
(如果第一台 Mac 提供共享打印队列,并且上述所有详细信息都与第一台 Mac 的设置相匹配,即使在第二台完全不同的 Mac 上,您也可以不加更改地运行此相同命令...)
<背景信息:
dns-sd
命令行实用程序是为每个接触 Bonjour、mDNS(多播 DNS)和DNS-SD(基于 DNS 的服务发现)。自 Bonjour 诞生以来,它已成为每个 OS X 系统的一部分。dns-sd
的-P
参数将向您的本地 LAN/WLAN 发出 Bonjour“代理公告”。该公告将告诉潜在的 AirPrint 客户以下信息:.local.
域中有可用的 AirPrint 设备。Airprint-abcd
。192.168.111.111
和端口631
访问。printers/abcd
进行打印。有关此实用程序的详细信息,请参阅
man dns-sd
。有关更多背景信息,请参阅 dns-sd.org 和 这些其他答案。Since you do not even show a starting point or stub of your code so far, here is a different hint: you can simulate a valid, working AirPrint service announcement in your local LAN/WLAN, which will allow your iOS clients to successfully print to an existing printer (AirPrint or not).
Requirements: a Mac with OS X.
Once you got this working, you can now use something like Wireshark or
tcpdump
to capture the packages on the wire or from the air and save and analyse them.Then start coding your own application and make it so that it emits the same packages as the simulation.
The following is known to work on OS X Yosemite (10.10.x).
Assuming,...
mymac
,192.168.111.111
,abcd
(does NOT need to be AirPrint-capable!), andDefaultAuthType none
into/etc/cups/cupsd.conf
),...then you can make the
abcd
queue available to iOS clients.To test this, just execute the following command in a Terminal.app window (attention, the command will not return -- if you close the Terminal.app window, the effect of the command will be gone!):
If this works (as it should), you can easily come up with a script or cron job which executes this command (and lets it run in the background) every time the Mac is booted up. This is left as an exercise to the reader.
(You could run this very same command unchanged even from a second, completely different Mac, if the first Mac is providing the shared print queue and all the details above match the first Mac's settings...)
Background info:
The
dns-sd
command line utility is meant as a testing and development tool for everybody poking into Bonjour, mDNS (multicast DNS) and DNS-SD (DNS-based Service Discovery). It is part of every OS X system since Bonjour came to life.The
-P
parameter todns-sd
will make a Bonjour "proxy announcement" to your local LAN/WLAN. The announcement will tell potential AirPrint clients the following info:.local.
domain.Airprint-abcd
.192.168.111.111
and port631
.printers/abcd
to print to it.For details about this utility see
man dns-sd
. For more background, see dns-sd.org and these other answers.