@@ -37,6 +37,9 @@ import UIKit
37
37
38
38
/// If true can scan and export multiple documents at onse, defaults to false
39
39
public var exportMultiple : Bool = false
40
+
41
+ ///Maximum number of scans. -1 for unlimited
42
+ public var maximumScans = - 1
40
43
41
44
/// Construct scanner object
42
45
public init ( presenter: UIViewController ) {
@@ -132,8 +135,15 @@ import UIKit
132
135
133
136
// perform perspective correction
134
137
if let flattened = photo. flattened ( rect: self . camera. observationRect) {
138
+
135
139
self . scannedImages. append ( flattened. noiseReducted. rotated)
136
-
140
+
141
+ if self . maximumScans != - 1
142
+ && self . scannedImages. count+ 1 >= self . maximumScans {
143
+ self . stopSession ( )
144
+ self . dismiss ? ( )
145
+ }
146
+
137
147
return
138
148
}
139
149
@@ -146,6 +156,7 @@ import UIKit
146
156
// return from manual cropping
147
157
cropView. onRetake = {
148
158
self . continueSession ( )
159
+ self . stopSession ( )
149
160
}
150
161
151
162
cropView. onRegionSave = {
@@ -157,6 +168,12 @@ import UIKit
157
168
if let flattened = photo. flattened ( rect: region) {
158
169
self . scannedImages. append ( flattened. noiseReducted. rotated)
159
170
171
+ if self . maximumScans != - 1
172
+ && self . scannedImages. count+ 1 >= self . maximumScans {
173
+ self . stopSession ( )
174
+ self . dismiss ? ( )
175
+ }
176
+
160
177
return
161
178
}
162
179
@@ -186,6 +203,12 @@ import UIKit
186
203
187
204
let croppedImage = photo. crop ( toPreviewLayer: camera. cameraLayer, withRect: regionRect)
188
205
scannedImages. append ( croppedImage. noiseReducted. rotated)
206
+
207
+ if self . maximumScans != - 1
208
+ && self . scannedImages. count+ 1 >= self . maximumScans {
209
+ self . stopSession ( )
210
+ self . dismiss ? ( )
211
+ }
189
212
}
190
213
191
214
private func toggleIdle( disabled: Bool ) {
0 commit comments