swiftuiprintinteractioncntrleruiprintinfo

Log list of available printers and their URLs


I am attempting to set up a UIPrinter instance so that my iPad app can print directly to that printer without having to present the print controller dialogue. The problem I'm having is that I can't seem to find the URL of this printer. It is connected via AirPrint.

Visiting http://localhost:631/printers/ does show the printer, but it shows the USB version of the printer's URL (i.e. usb://Brother/QL-710W?serial=12345).

What I am wondering is, how can I print (to the debug output) a list of my available printers, and their URLs? I figure by doing this I can then locate my printer's AirPrint URL and go from there.

Thanks!


Solution

  • Here's a simplified version in Swift 3 for anyone stumbling upon this same question in 2017:

    let pickerController = UIPrinterPickerController(initiallySelectedPrinter: nil)
    
    pickerController.present(animated: true) { (controller, completed, error) in
        if completed == true {
            print(controller.selectedPrinter!.url)
        }
    }