How can i add ip address to print object and print, they are on the same wi-fi but i always get error code 4?

227 Views Asked by At

Print from iPhone with ip address via air print

 let printController = UIPrintInteractionController.shared
    let printInfo = UIPrintInfo(dictionary: nil)
    printInfo.outputType = UIPrintInfo.OutputType.general
    printInfo.orientation = UIPrintInfo.Orientation.portrait
    printInfo.jobName = "print Job"
    let textWithNewCarriageReturns = text.replacingOccurrences(of: "\n", with: "<br /> <br />")
    let formatter = UIMarkupTextPrintFormatter(markupText: textWithNewCarriageReturns)
    formatter.perPageContentInsets = UIEdgeInsets(top: 70, left: 70, bottom: 70, right: 70)
    printController.printingItem = text
    printController.printInfo = printInfo
    guard let printerIP = URL(string: "https://192.168.1.54") else {fatalError("missing url")}
    let printer = UIPrinter(url: printerIP)
    printController.print(to: printer, completionHandler: {(controller, success, error) -> Void in
        if success {
            debugPrint("Printing Completed.")
        } else {
            debugPrint("Printing Failed. \(error?.localizedDescription as Any)")
        }
    })

Printing Failed. Optional(\"The operation couldn’t be completed. (UIPrintErrorDomain error 4.)\")"

0

There are 0 best solutions below