Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List accessible AirPrint Printers

I would like to show a list with all printer accessible by the device via AirPrint.

I get it working with using the UIPrinterPickerController.

Is there anyway displaying this PickerController in a custom way, let's say feeding the data into a UITableView?

Also note that I'm planning to use this App on an iPad which only supports the UIPrinterPickerController.presentFromRect(CGRect)

Here's how it looks right now. Instead of this popup there should be a UITableView

Printer Popup

like image 386
smnk Avatar asked Aug 15 '16 11:08

smnk


1 Answers

the NSNetServiceBrowser is precisely for this.

In short, what you need to do is:

1) set an object as the NSNetServiceBrowserDelegate 2) create a NSNetServiceBrowser object 3) assign the delegate 4) using browserObject.searchForServices(ofType: "_printer._tcp.", inDomain: "") will get various feedback to the delegate.

A simple test on my end got:

didFind: Samsung C460 Series (SEC001174EDCB63)

for the delegate method:

func netServiceBrowser(_ browser: NetServiceBrowser, didFind service: NetService, moreComing: Bool) {
    print("didFind: \(service.name)")
}
like image 133
Adrian Sluyters Avatar answered Oct 20 '22 01:10

Adrian Sluyters