iosswiftxcodeairprint

UIPrinterPickerController not showing on iOS 13


I've been trying to get a UIPrinterPicker to show up but for some reason it just never does. The completion handler gets called immediately. The UIPrintInteractionController shows up just fine but this one refuses to show for some reason. This is the code I am using currently

    let picker = UIPrinterPickerController(initiallySelectedPrinter: nil)
    picker.present(animated: true) { (controller, complete, error) in
        print("done")
    }

Solution

  • Implement UIPrinterPickerControllerDelegate so it works for iOS 13 https://developer.apple.com/documentation/uikit/uiprinterpickercontroller/1620514-present

    class ViewController: UIViewController {
    
        @IBAction func btnTapped(_ sender: Any) {
            let picker = UIPrinterPickerController(initiallySelectedPrinter: nil)
            picker.delegate = self
            picker.present(animated: true) { (controller, complete, error) in
                print("done")
            }
        }
    }
    
    // MARK:- UIPrinterPickerControllerDelegate
    extension ViewController: UIPrinterPickerControllerDelegate {
        func printerPickerControllerParentViewController(_ printerPickerController: UIPrinterPickerController) -> UIViewController? {
            return self
        }
    }