From df6f707fc3c78b47ab3d1ba8e598f85a70838023 Mon Sep 17 00:00:00 2001 From: Mahdi Ghorbani Date: Mon, 21 Oct 2024 15:33:37 +0330 Subject: [PATCH] reallocate documentScanner on each call (#134) --- ios/DocumentScanner.swift | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ios/DocumentScanner.swift b/ios/DocumentScanner.swift index 237ca8c..88267e1 100644 --- a/ios/DocumentScanner.swift +++ b/ios/DocumentScanner.swift @@ -7,7 +7,7 @@ class DocumentScanner: NSObject { } /** @property documentScanner the document scanner */ - let documentScanner = DocScanner() + private var documentScanner: DocScanner? @objc(scanDocument:withResolver:withRejecter:) func scanDocument( @@ -16,8 +16,10 @@ class DocumentScanner: NSObject { reject: @escaping RCTPromiseRejectBlock ) -> Void { DispatchQueue.main.async { + self.documentScanner = DocScanner() + // launch the document scanner - self.documentScanner.startScan( + self.documentScanner?.startScan( RCTPresentedViewController(), successHandler: { (scannedDocumentImages: [String]) in // document scan success @@ -25,16 +27,19 @@ class DocumentScanner: NSObject { "status": "success", "scannedImages": scannedDocumentImages ]) + self.documentScanner = nil }, errorHandler: { (errorMessage: String) in // document scan error reject("document scan error", errorMessage, nil) + self.documentScanner = nil }, cancelHandler: { // when user cancels document scan resolve([ "status": "cancel" ]) + self.documentScanner = nil }, responseType: options["responseType"] as? String, croppedImageQuality: options["croppedImageQuality"] as? Int