通过空中打印从具有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。)\”)“