我如何添加ip地址以打印对象并进行打印,它们位于同一wi-fi上,但我总是收到错误代码4?

时间:2019-06-06 15:00:50

标签: ios swift uiprintinteractioncntrler uiprintformatter uiprintinfo

通过空中打印从具有IP地址的iPhone打印

 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)")
        }
    })

打印失败。可选(\“该操作无法完成。(UIPrintErrorDomain错误4。)\”)“

0 个答案:

没有答案