qrdnicapacitor 1.0.12 → 1.0.13
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.
|
@@ -89,7 +89,7 @@ public class QrCodeScanner extends AppCompatActivity {
|
|
|
89
89
|
if (returnString) {
|
|
90
90
|
handled = true;
|
|
91
91
|
Intent intent = new Intent();
|
|
92
|
-
intent.putExtra(
|
|
92
|
+
intent.putExtra(KEY_QR_CODE, normalizeText(rawResult.getText()));
|
|
93
93
|
setResult(RESULT_OK, intent);
|
|
94
94
|
finish();
|
|
95
95
|
} else {
|
|
@@ -103,7 +103,7 @@ public class QrCodeScanner extends AppCompatActivity {
|
|
|
103
103
|
Log.d("QrCodeScanner", "Bytes leídos: " + rawBytes.length);
|
|
104
104
|
|
|
105
105
|
Intent intent = new Intent();
|
|
106
|
-
intent.putExtra(
|
|
106
|
+
intent.putExtra(KEY_QR_CODE, base64Result);
|
|
107
107
|
setResult(RESULT_OK, intent);
|
|
108
108
|
finish();
|
|
109
109
|
} else {
|
|
@@ -14,6 +14,13 @@ public class qrdniPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
14
14
|
|
|
15
15
|
// PROPIEDAD PARA GUARDAR LA LLAMADA (Plan B)
|
|
16
16
|
private var scanCall: CAPPluginCall?
|
|
17
|
+
private var scannerVC: ScannerViewController?
|
|
18
|
+
|
|
19
|
+
override func viewDidDisappear(_ animated: Bool) {
|
|
20
|
+
super.viewDidDisappear(animated)
|
|
21
|
+
// Si se cierra sin haber emitido resultado, notificar cancelación
|
|
22
|
+
NotificationCenter.default.post(name: NSNotification.Name("lecturaQRCancelada"), object: nil)
|
|
23
|
+
}
|
|
17
24
|
|
|
18
25
|
@objc func configure(_ call: CAPPluginCall) {
|
|
19
26
|
let license = call.getString("license") ?? ""
|
|
@@ -56,49 +63,56 @@ public class qrdniPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
56
63
|
let scannerVC = ScannerViewController()
|
|
57
64
|
scannerVC.modalPresentationStyle = .fullScreen
|
|
58
65
|
scannerVC.inicializa(returnString: false)
|
|
59
|
-
|
|
66
|
+
self.scannerVC = scannerVC
|
|
67
|
+
|
|
60
68
|
NotificationCenter.default.addObserver(self, selector: #selector(self.handleScannerResult(_:)), name: NSNotification.Name("lecturaQR"), object: nil)
|
|
61
69
|
|
|
62
70
|
self.bridge?.viewController?.present(scannerVC, animated: true)
|
|
63
71
|
}
|
|
64
72
|
}
|
|
73
|
+
@objc func handleScannerResult(_ notification: Notification) {
|
|
74
|
+
NotificationCenter.default.removeObserver(self, name: NSNotification.Name("lecturaQR"), object: nil)
|
|
65
75
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
print("ERROR: La referencia local a la llamada es nil")
|
|
72
|
-
return
|
|
73
|
-
}
|
|
76
|
+
// Cerrar el scanner
|
|
77
|
+
DispatchQueue.main.async { [weak self] in
|
|
78
|
+
self?.scannerVC?.dismiss(animated: true)
|
|
79
|
+
self?.scannerVC = nil
|
|
80
|
+
}
|
|
74
81
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
82
|
+
guard let call = self.scanCall else {
|
|
83
|
+
print("ERROR: La referencia local a la llamada es nil")
|
|
84
|
+
return
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// El scanner publica "qrcodeData" (Data) en modo DNI,
|
|
88
|
+
// o "qrcode" (String) en modo texto. Aceptamos ambos.
|
|
89
|
+
var qrData: Data? = nil
|
|
90
|
+
if let userInfo = notification.userInfo {
|
|
91
|
+
if let d = userInfo["qrcodeData"] as? Data {
|
|
92
|
+
qrData = d
|
|
93
|
+
} else if let s = userInfo["qrcode"] as? String {
|
|
94
|
+
qrData = Data(base64Encoded: s)
|
|
80
95
|
}
|
|
96
|
+
}
|
|
81
97
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
self.scanCall = nil
|
|
101
|
-
}
|
|
98
|
+
guard let datos = qrData else {
|
|
99
|
+
call.reject("Error al obtener datos")
|
|
100
|
+
self.scanCall = nil
|
|
101
|
+
return
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
DispatchQueue.global(qos: .userInitiated).async { [weak self] in
|
|
105
|
+
guard let self = self else { return }
|
|
106
|
+
|
|
107
|
+
if let resultadoJson = self.implementation.validaMiDNIQR(datosQR: datos) {
|
|
108
|
+
DispatchQueue.main.async {
|
|
109
|
+
call.resolve(resultadoJson)
|
|
110
|
+
self.scanCall = nil
|
|
111
|
+
}
|
|
112
|
+
} else {
|
|
113
|
+
DispatchQueue.main.async {
|
|
114
|
+
call.reject("Fallo en validación")
|
|
115
|
+
self.scanCall = nil
|
|
102
116
|
}
|
|
103
117
|
}
|
|
104
118
|
}
|