6

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

smnk
  • 471
  • 1
  • 6
  • 25
  • 2
    I'm wondering if with `printerPickerController:shouldShowPrinter:` you can retrieve all the `UIPrinter`, since it should get called for each printers. You may have to call the show the `UIPrinterPickerController` (and hide it, or in a invisible part of the screen, quick dismiss, I don't know when the delegate method should be call, i.e.. if cell willShow, or already set) in order that the previous method of `UIPrinterPickerControllerDelegate` gets called. – Larme Sep 01 '16 at 09:19

1 Answers1

2

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)")
}
Adrian Sluyters
  • 2,186
  • 1
  • 16
  • 21
  • This is looking good so far. Can only test next week though, since I myself don't have any AirPrint printers – smnk Sep 03 '16 at 08:36
  • For those like me who tried to understand this answer without a good knowledge of objective-c / swift, beware that this is explained with more details under https://developer.apple.com/library/content/documentation/Networking/Conceptual/NSNetServiceProgGuide/Articles/BrowsingForServices.html. – Laurent Michel Aug 20 '17 at 07:16