@@ -37,6 +37,9 @@ import UIKit
3737
3838 /// If true can scan and export multiple documents at onse, defaults to false
3939 public var exportMultiple : Bool = false
40+
41+ ///Maximum number of scans. -1 for unlimited
42+ public var maximumScans = - 1
4043
4144 /// Construct scanner object
4245 public init ( presenter: UIViewController ) {
@@ -132,8 +135,15 @@ import UIKit
132135
133136 // perform perspective correction
134137 if let flattened = photo. flattened ( rect: self . camera. observationRect) {
138+
135139 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+
137147 return
138148 }
139149
@@ -146,6 +156,7 @@ import UIKit
146156 // return from manual cropping
147157 cropView. onRetake = {
148158 self . continueSession ( )
159+ self . stopSession ( )
149160 }
150161
151162 cropView. onRegionSave = {
@@ -157,6 +168,12 @@ import UIKit
157168 if let flattened = photo. flattened ( rect: region) {
158169 self . scannedImages. append ( flattened. noiseReducted. rotated)
159170
171+ if self . maximumScans != - 1
172+ && self . scannedImages. count+ 1 >= self . maximumScans {
173+ self . stopSession ( )
174+ self . dismiss ? ( )
175+ }
176+
160177 return
161178 }
162179
@@ -186,6 +203,12 @@ import UIKit
186203
187204 let croppedImage = photo. crop ( toPreviewLayer: camera. cameraLayer, withRect: regionRect)
188205 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+ }
189212 }
190213
191214 private func toggleIdle( disabled: Bool ) {
0 commit comments