@ruhiverse/thermal-printer-plugin 1.0.4 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -28,11 +28,8 @@ public class ThermalPrinterPlugin: CAPPlugin, CBCentralManagerDelegate, CBPeriph
|
|
|
28
28
|
private var targetPrintAddress: String?
|
|
29
29
|
|
|
30
30
|
// Common BLE service UUIDs for thermal printers (Serial Port Profile)
|
|
31
|
+
// Note: We scan with nil services to find all peripherals, then filter by name
|
|
31
32
|
private let serialPortServiceUUID = CBUUID(string: "00001101-0000-1000-8000-00805F9B34FB") // SPP
|
|
32
|
-
private let commonPrinterServiceUUIDs = [
|
|
33
|
-
CBUUID(string: "00001101-0000-1000-8000-00805F9B34FB"), // SPP
|
|
34
|
-
CBUUID(string: "E7810A71-73AE-499D-8C15-DAA9080B0E"), // Some thermal printers
|
|
35
|
-
]
|
|
36
33
|
|
|
37
34
|
/// Find a connected External Accessory that matches the given (optional) name
|
|
38
35
|
/// and supports one of the known printer protocols.
|
|
@@ -208,37 +205,38 @@ public class ThermalPrinterPlugin: CAPPlugin, CBCentralManagerDelegate, CBPeriph
|
|
|
208
205
|
}
|
|
209
206
|
|
|
210
207
|
// Find peripheral by identifier
|
|
211
|
-
if let uuid = UUID(uuidString: address)
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
208
|
+
if let uuid = UUID(uuidString: address) {
|
|
209
|
+
let peripherals = centralManager.retrievePeripherals(withIdentifiers: [uuid])
|
|
210
|
+
if let peripheral = peripherals.first {
|
|
211
|
+
// Found in known peripherals, connect directly
|
|
212
|
+
printData = data
|
|
213
|
+
printCompletion = { success, error in
|
|
214
|
+
if success {
|
|
215
|
+
DispatchQueue.main.async {
|
|
216
|
+
call.resolve([
|
|
217
|
+
"success": true,
|
|
218
|
+
"message": "Bluetooth print data sent to printer (BLE).",
|
|
219
|
+
])
|
|
220
|
+
}
|
|
221
|
+
} else {
|
|
222
|
+
DispatchQueue.main.async {
|
|
223
|
+
call.reject("BLE print failed: \(error ?? "Unknown error")")
|
|
224
|
+
}
|
|
223
225
|
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
connectedPeripheral = peripheral
|
|
229
|
+
peripheral.delegate = self
|
|
230
|
+
|
|
231
|
+
if centralManager.state == .poweredOn {
|
|
232
|
+
centralManager.connect(peripheral, options: nil)
|
|
224
233
|
} else {
|
|
225
234
|
DispatchQueue.main.async {
|
|
226
|
-
call.reject("
|
|
235
|
+
call.reject("Bluetooth is not powered on")
|
|
227
236
|
}
|
|
228
237
|
}
|
|
238
|
+
return
|
|
229
239
|
}
|
|
230
|
-
|
|
231
|
-
connectedPeripheral = peripheral
|
|
232
|
-
peripheral.delegate = self
|
|
233
|
-
|
|
234
|
-
if centralManager.state == .poweredOn {
|
|
235
|
-
centralManager.connect(peripheral, options: nil)
|
|
236
|
-
} else {
|
|
237
|
-
DispatchQueue.main.async {
|
|
238
|
-
call.reject("Bluetooth is not powered on")
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
return
|
|
242
240
|
}
|
|
243
241
|
|
|
244
242
|
// Not found in known peripherals, scan for it
|