これが私がしたことです。
Global Var
var ReceiptPrinterHolder = NSURL()
var currentPrinter: UIPrinter?
var ReceiptPrinter: UIPrinter?
func Works(){
let printerPicker = UIPrinterPickerController(initiallySelectedPrinter: currentPrinter2)
printerPicker.presentFromRect(CGRectMake(0, 0, 300, 500), inView: view, animated: true, completionHandler: {
(printerPicker, userDidSelect, error) in
if userDidSelect {
var selectedPrinter: UIPrinter? { return printerPicker.selectedPrinter }
currentPrinter = selectedPrinter
self.DisplaySelectedAction()
}else{
print("Did not work")
}
})
// return currentPrinter2!
}
@IBAction func ReceiptPrinterAction() {
Works()
if currentPrinter != nil {
Label2.text = "Receipt Printer \(ReceiptPrinter!.displayName)"
ReceiptPrinter = currentPrinter
ReceiptPrinterHolder = ReceiptPrinter!.URL
}
}