-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathDocumentAcknowledgmentUI2ViewController.swift
More file actions
101 lines (78 loc) · 4.32 KB
/
Copy pathDocumentAcknowledgmentUI2ViewController.swift
File metadata and controls
101 lines (78 loc) · 4.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
//
// DocumentAcknowledgmentUI2ViewController.swift
// ScanbotSDK Examples
//
// Created by Rana Sohaib on 16.07.24.
//
import Foundation
import ScanbotSDK
class DocumentAcknowledgmentUI2ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Start scanning here. Usually this is an action triggered by some button or menu.
Task {
await self.startScanning()
}
}
func startScanning() async {
// Create the default configuration object.
let configuration = SBSDKUI2DocumentScanningFlow()
// Set the acknowledgment mode
// Modes:
// - `always`: Runs the quality analyzer on the captured document and always displays the acknowledgment screen.
// - `badQuality`: Runs the quality analyzer and displays the acknowledgment screen only if the quality is poor.
// - `none`: Skips the quality check entirely.
configuration.screens.camera.acknowledgement.acknowledgementMode = .always
// Set the minimum threshold of unacceptable and uncertain qualities.
configuration.screens.camera.documentQualityAnalyzerConfiguration.qualityUnacceptableUncertainThreshold = 0.75
// Set the background color for the acknowledgment screen.
configuration.screens.camera.acknowledgement.backgroundColor = SBSDKUI2Color(colorString: "#EFEFEF")
// You can also configure the buttons in the bottom bar of the acknowledgment screen.
// E.g. to force the user to retake, if the captured document is not acceptable.
configuration.screens.camera.acknowledgement.bottomBar.acceptWhenAcceptableButton.visible = false
// Hide the titles of the buttons.
configuration.screens.camera.acknowledgement.bottomBar.acceptWhenAcceptableButton.title.visible = false
configuration.screens.camera.acknowledgement.bottomBar.acceptWhenAcceptableButton.title.visible = false
configuration.screens.camera.acknowledgement.bottomBar.retakeButton.title.visible = false
// Configure the acknowledgment screen's hint message which is shown if the least acceptable quality is not met.
configuration.screens.camera.acknowledgement.unacceptableQualityWarning.visible = true
// Present the view controller modally.
do {
let result = try await SBSDKUI2DocumentScannerController.present(on: self, configuration: configuration)
// Handle the result.
print(result.uuid)
print(result.pageCount)
print(result.documentImageSizeLimit)
print(result.pdfURI)
print(result.tiffURI)
print(result.creationDate)
// Check out other available properties in `SBSDKScannedDocument`.
result.pages.forEach { scannedPage in
print(scannedPage.uuid)
print(scannedPage.documentDetectionStatus)
print(scannedPage.polygon)
print(scannedPage.source)
let originalImage = scannedPage.originalImage
let originalImageURI = scannedPage.originalImageURI
let documentImage = scannedPage.documentImage
let documentImageURI = scannedPage.documentImageURI
let documentImagePreview = scannedPage.documentImagePreview
let documentImagePreviewURI = scannedPage.documentImagePreviewURI
if let documentQuality = scannedPage.documentQualityAssessment {
switch documentQuality {
case .acceptable: print("acceptable")
case .unacceptable: print("unacceptable")
case .uncertain: print("uncertain")
default: print("unknown")
}
}
// Check out other available properties in `SBSDKScannedPage`
}
} catch SBSDKError.operationCanceled {
print("The operation was cancelled before completion or by the user")
} catch {
// Any other error
print("Error scanning document: \(error.localizedDescription)")
}
}
}