Skip to content

Commit df6f707

Browse files
authored
reallocate documentScanner on each call (#134)
1 parent 12ce511 commit df6f707

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

ios/DocumentScanner.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class DocumentScanner: NSObject {
77
}
88

99
/** @property documentScanner the document scanner */
10-
let documentScanner = DocScanner()
10+
private var documentScanner: DocScanner?
1111

1212
@objc(scanDocument:withResolver:withRejecter:)
1313
func scanDocument(
@@ -16,25 +16,30 @@ class DocumentScanner: NSObject {
1616
reject: @escaping RCTPromiseRejectBlock
1717
) -> Void {
1818
DispatchQueue.main.async {
19+
self.documentScanner = DocScanner()
20+
1921
// launch the document scanner
20-
self.documentScanner.startScan(
22+
self.documentScanner?.startScan(
2123
RCTPresentedViewController(),
2224
successHandler: { (scannedDocumentImages: [String]) in
2325
// document scan success
2426
resolve([
2527
"status": "success",
2628
"scannedImages": scannedDocumentImages
2729
])
30+
self.documentScanner = nil
2831
},
2932
errorHandler: { (errorMessage: String) in
3033
// document scan error
3134
reject("document scan error", errorMessage, nil)
35+
self.documentScanner = nil
3236
},
3337
cancelHandler: {
3438
// when user cancels document scan
3539
resolve([
3640
"status": "cancel"
3741
])
42+
self.documentScanner = nil
3843
},
3944
responseType: options["responseType"] as? String,
4045
croppedImageQuality: options["croppedImageQuality"] as? Int

0 commit comments

Comments
 (0)