在iOS设备中创建Bonjour AirPrint服务 [英] Creating a Bonjour AirPrint service in iOS device

查看:875
本文介绍了在iOS设备中创建Bonjour AirPrint服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我想到要将iOS服务作为打印机发布(宣布服务),我使用NSNetService并将类型设置为 _ipp._tcp

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.

但为了被认可为AirPrint打印机,要求包括:

But in order to be recognized as an AirPrint printer the requirements include:


  • AirPrint使用IPP进行打印管理。

  • AirPrint收听mDNS(Bonjour / Avahi)进行打印机发现。

  • AirPrint需要 _universal 子类型将出现在 _ipp 公告中,然后才会考虑列出打印机。

  • AirPrint要求一个额外的TXT记录,URF,在考虑列出打印机之前存在且非空。

  • 虽然这种URF格式(见下文)似乎是未来的选择Apple,所有目前支持AirPrint的应用程序似乎都以PDF格式发送打印数据。

  • 当打印机受到用户名/密码的保护时,iTunes / AirPrint守护程序将发送TXT记录air =用户名,密码。

  • 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".

来源

所以我试图弄清楚如何发布子类型并在NSNetService下发布我无法做到的TXT记录。任何人都有任何想法?

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?

推荐答案

因为到目前为止您甚至没有显示代码的起点或存根,所以这是一个不同的提示:您可以在本地LAN / WLAN中模拟有效的,正常工作的AirPrint服务公告,这将允许您的iOS客户端成功打印到现有的打印机(AirPrint与否)。

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

要求:带OS X的Mac。

Requirements: a Mac with OS X.

一旦你开始工作,你现在可以使用Wireshark或 tcpdump 用于捕获电线或空中的包并保存和分析它们。

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.

以下已知适用于OS X Yosemite(10.10.x)。

The following is known to work on OS X Yosemite (10.10.x).

假设,...


  • 你有运行OS的Mac(Book) X,

  • 此Mac的主机名为 mymac

  • 其IP地址 192.168.111.111

  • 它安装了共享打印机名为 abcd NOT 需要支持AirPrint!)和

  • 打印机共享不需要身份验证(放 DefaultAuthType none 进入 /etc/cups/cupsd.conf ),

  • you have a Mac(Book) running OS X,
  • this Mac's hostname is mymac,
  • its IP address is 192.168.111.111,
  • it has a shared printer installed named abcd (does NOT need to be AirPrint-capable!), and
  • the printer share requires no authentication (put DefaultAuthType none into /etc/cups/cupsd.conf),

...然后你可以让iOS客户端可以使用 abcd 队列。

...then you can make the abcd queue available to iOS clients.

为了测试这个,只需在Terminal.app窗口中执行以下命令(注意,该命令不会返回 - 如果关闭Terminal.app窗口,该命令的效果将消失!):

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!):

 dns-sd                 \
   -P AirPrint-abcd     \
   _ipp._tcp,_universal \
   local.               \
   631                  \
   mymac.local.         \
   192.168.111.111      \
         pdl="application/pdf,image/urf"    \
         kind="document"                    \
         priority="1"                       \
         product="Model Name of my Printer" \
         rp="printers/abcd"                 \
         URF="DM3"                          \
         Duplex="T"                         \
         Color="T"                          \
         note="Testing AirPrint via MacBook"\
         txtvers="1"                        \
         qtotal="1"                         \
         printer-type="0x0480FFFC"          \
         printer-state="3"                  \
         air="none"                         \
         UUID="54321abc-1234-1234-abcd-1238e4babcd8"

如果这样做(应该如此),您可以轻松地提出脚本或cron作业WH每次启动Mac时,都会执行此命令(并让它在后台运行)。这是留给读者的一个练习。

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.

(你可以运行这个相同的命令,即使是第二个完全不同的Mac,如果第一台Mac也是如此正在提供共享打印队列,上面的所有细节都与第一个Mac的设置相匹配......)

背景信息:

dns-sd 命令line实用程序是一种测试和开发工具,适用于所有人进入Bonjour,mDNS(多播DNS)和DNS-SD(基于DNS的服务发现)。自Bonjour复活以来,它是每个OS X系统的一部分。

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.

-P 参数 dns-sd 将向您的本地LAN / WLAN发出Bonjour代理公告。该公告将告知潜在的AirPrint客户以下信息:

The -P parameter to dns-sd will make a Bonjour "proxy announcement" to your local LAN/WLAN. The announcement will tell potential AirPrint clients the following info:


  • 您的 .local中有一个AirPrint设备。 域。

  • 其名称为 Airprint-abcd

  • 可以通过IP地址 192.168.111.111 和端口 631 来访问。

  • 使用打印队列名称 printers / abcd 打印到它。

  • 它可以使用PDF和URF光栅文档。

  • 它不需要身份验证。

  • 它可以输出双面和彩色文档。

  • There is an AirPrint device available in your .local. domain.
  • Its name is Airprint-abcd.
  • It can be reached via IP address 192.168.111.111 and port 631.
  • Use the print queue name of printers/abcd to print to it.
  • It can consume PDF and URF raster documents.
  • It does not need authentication.
  • It can output duplex and color documents.

有关此实用程序的详细信息,请参阅 man dns-sd 。有关更多背景信息,请参阅 dns-sd.org 这些其他答案

For details about this utility see man dns-sd. For more background, see dns-sd.org and these other answers.

这篇关于在iOS设备中创建Bonjour AirPrint服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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