David PHAM-VAN

Fix directPrint issue with iOS 15

@@ -13,6 +13,7 @@ @@ -13,6 +13,7 @@
13 - Enable usage of printer's settings on Windows [Alban Lecuivre] 13 - Enable usage of printer's settings on Windows [Alban Lecuivre]
14 - Update android projects (mavenCentral, compileSdkVersion 30, gradle:4.1.0) 14 - Update android projects (mavenCentral, compileSdkVersion 30, gradle:4.1.0)
15 - Use syscall(SYS_memfd_create) instead of glibc function memfd_create [Obezyan] 15 - Use syscall(SYS_memfd_create) instead of glibc function memfd_create [Obezyan]
  16 +- Fix directPrint issue with iOS 15
16 17
17 ## 5.6.6 18 ## 5.6.6
18 19
@@ -70,20 +70,20 @@ public class PrintJob: UIPrintPageRenderer, UIPrintInteractionControllerDelegate @@ -70,20 +70,20 @@ public class PrintJob: UIPrintPageRenderer, UIPrintInteractionControllerDelegate
70 return 70 return
71 } 71 }
72 72
73 - let controller = UIPrintInteractionController.shared  
74 - controller.delegate = self  
75 -  
76 - let printInfo = UIPrintInfo.printInfo()  
77 - printInfo.jobName = jobName!  
78 - DispatchQueue.main.async { printInfo.outputType = .general }  
79 - if orientation != nil {  
80 - printInfo.orientation = orientation!  
81 - orientation = nil  
82 - }  
83 - controller.printInfo = printInfo  
84 - controller.printPageRenderer = self 73 + DispatchQueue.main.async { [self] in
  74 + let controller = UIPrintInteractionController.shared
  75 + controller.delegate = self
  76 +
  77 + let printInfo = UIPrintInfo.printInfo()
  78 + printInfo.jobName = jobName!
  79 + printInfo.outputType = .general
  80 + if orientation != nil {
  81 + printInfo.orientation = orientation!
  82 + orientation = nil
  83 + }
  84 + controller.printInfo = printInfo
  85 + controller.printPageRenderer = self
85 86
86 - DispatchQueue.main.async {  
87 if self.printerName != nil { 87 if self.printerName != nil {
88 let printerURL = URL(string: self.printerName!) 88 let printerURL = URL(string: self.printerName!)
89 89
@@ -93,7 +93,14 @@ public class PrintJob: UIPrintPageRenderer, UIPrintInteractionControllerDelegate @@ -93,7 +93,14 @@ public class PrintJob: UIPrintPageRenderer, UIPrintInteractionControllerDelegate
93 } 93 }
94 94
95 let printer = UIPrinter(url: printerURL!) 95 let printer = UIPrinter(url: printerURL!)
96 - controller.print(to: printer, completionHandler: self.completionHandler) 96 + printer.contactPrinter { available -> Void in
  97 + if !available {
  98 + printing.onCompleted(printJob: self, completed: false, error: "Printer not available")
  99 + return
  100 + }
  101 +
  102 + controller.print(to: printer, completionHandler: self.completionHandler)
  103 + }
97 } else { 104 } else {
98 controller.present(animated: true, completionHandler: self.completionHandler) 105 controller.present(animated: true, completionHandler: self.completionHandler)
99 } 106 }