-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathDocumentIntroductionUI2ViewController.swift
More file actions
112 lines (84 loc) · 4.39 KB
/
Copy pathDocumentIntroductionUI2ViewController.swift
File metadata and controls
112 lines (84 loc) · 4.39 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
102
103
104
105
106
107
108
109
110
111
112
//
// DocumentIntroductionUI2ViewController.swift
// ScanbotSDK Examples
//
// Created by Seifeddine Bouzid on 05.08.24.
//
import Foundation
import ScanbotSDK
class DocumentIntroductionUI2ViewController: 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()
// Retrieve the instance of the introduction configuration from the main configuration object.
let introductionConfiguration = configuration.screens.camera.introduction
// Show the introduction screen automatically when the screen appears.
introductionConfiguration.showAutomatically = true
// Create a new introduction item.
let firstExampleEntry = SBSDKUI2IntroListEntry()
// Configure the introduction image to be shown.
firstExampleEntry.image = .receiptsIntroImage()
// Configure the text.
firstExampleEntry.text = SBSDKUI2StyledText(text: "Some text explaining how to scan a receipt",
color: SBSDKUI2Color(colorString: "#000000"))
// Create a second introduction item.
let secondExampleEntry = SBSDKUI2IntroListEntry()
// Configure the introduction image to be shown.
secondExampleEntry.image = .checkIntroImage()
// Configure the text.
secondExampleEntry.text = SBSDKUI2StyledText(text: "Some text explaining how to scan a check",
color: SBSDKUI2Color(colorString: "#000000"))
// Set the items into the configuration.
introductionConfiguration.items = [firstExampleEntry, secondExampleEntry]
// Set the screen title.
introductionConfiguration.title = SBSDKUI2StyledText(text: "Introduction",
color: SBSDKUI2Color(colorString: "#000000"))
// Apply the introduction configuration.
configuration.screens.camera.introduction = introductionConfiguration
// 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)")
}
}
}