gpt4 book ai didi

iOS Airprint 不使用打印机选择界面

转载 作者:行者123 更新时间:2023-11-28 06:04:21 37 4
gpt4 key购买 nike

我正在制作一个应用程序,用户首先选择默认打印机,然后在单击“打印”按钮时继续,照片会自动打印,无需任何对话框。下面是我的代码。我收到错误消息“PrintViewController 没有初始化程序”

class PrintViewController: UIViewController {

var defaultPrinter : UIPrinter

override func viewDidLoad() {
super.viewDidLoad()

// Do any additional setup after loading the view.
}


func SelecteDefaultPrinter(){
let printerPicker = UIPrinterPickerController(initiallySelectedPrinter: nil)
printerPicker.present(from: CGRect(x: 0, y: 0, width: 600, height: 500), in: self.view, animated: true) { (printerPicker, userDidSelect, error) in
if userDidSelect {
//Here get the selected UIPrinter
self.defaultPrinter = printerPicker.selectedPrinter!
}
}
}


@IBAction func Button_DefaultPrinter(_ sender: Any) {
SelecteDefaultPrinter()
}

//In your view controller
@IBAction func printButton(sender: AnyObject) {

let printInfo = UIPrintInfo(dictionary:nil)
printInfo.outputType = UIPrintInfoOutputType.general
printInfo.jobName = "Test Print"

// Set up print controller
let printController = UIPrintInteractionController.shared
printController.printInfo = printInfo

// Assign a UIImage version of my UIView as a printing iten
printController.printingItem = self.view.toImage()

// Assign a Specific Image to printing item
//printController.printingItem = customImageView.image

// Print With Dialogue Box
//printController.present(from: self.view.frame, in: self.view, animated: true, completionHandler: nil)


// Print Without Dialogue Box
printController.print(to: defaultPrinter, completionHandler: {(controller, success, error) -> Void in
if success {
debugPrint("Printing Completed.")
} else {
debugPrint("Printing Failed.")
}
})
}

最佳答案

解决了!这是错误的

var defaultPrinter : UIPrinter!

它正在吞噬我的大脑。 :D

关于iOS Airprint 不使用打印机选择界面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48661158/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com